flipper-redis 0.28.0 → 0.28.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/flipper/adapters/redis.rb +31 -19
- data/lib/flipper/version.rb +1 -1
- data/spec/flipper/adapters/redis_spec.rb +24 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da947e5db80b4463e7c86ff89737646c6906a40655cc6e645d72034c54c5a668
|
4
|
+
data.tar.gz: 1b986261a557e1ebc6960e1143dc508329f51e62b60ac8e15647a941ea85e881
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6694f4bdc0a4ab3c2a4efaf77c7cef61f4934e2274ba0942968fd9fb87d3feeb65353c43c8e46b76b15bad5fd22db6cefd976e77f0a48f0eaa80ddc6d8059e53
|
7
|
+
data.tar.gz: b7a853325307fa9ca03a063a70194860dcc0abab55bca29d2e4114fa12d240748a6563bb601839324ebc49f60bc7f87ae1000d13f17285a654c8670ec425cb28
|
@@ -7,18 +7,28 @@ module Flipper
|
|
7
7
|
class Redis
|
8
8
|
include ::Flipper::Adapter
|
9
9
|
|
10
|
-
# Private: The key that stores the set of known features.
|
11
|
-
FeaturesKey = :flipper_features
|
12
|
-
|
13
10
|
# Public: The name of the adapter.
|
14
11
|
attr_reader :name
|
15
12
|
|
13
|
+
attr_reader :key_prefix
|
14
|
+
|
15
|
+
def features_key
|
16
|
+
"#{key_prefix}flipper_features"
|
17
|
+
end
|
18
|
+
|
19
|
+
def key_for(feature_name)
|
20
|
+
"#{key_prefix}#{feature_name}"
|
21
|
+
end
|
22
|
+
|
16
23
|
# Public: Initializes a Redis flipper adapter.
|
17
24
|
#
|
18
|
-
# client - The Redis client to use.
|
19
|
-
|
25
|
+
# client - The Redis client to use.
|
26
|
+
# key_prefix - an optional prefix with which to namespace
|
27
|
+
# flipper's Redis keys
|
28
|
+
def initialize(client, key_prefix: nil)
|
20
29
|
@client = client
|
21
30
|
@name = :redis
|
31
|
+
@key_prefix = key_prefix
|
22
32
|
end
|
23
33
|
|
24
34
|
# Public: The set of known features.
|
@@ -29,9 +39,9 @@ module Flipper
|
|
29
39
|
# Public: Adds a feature to the set of known features.
|
30
40
|
def add(feature)
|
31
41
|
if redis_sadd_returns_boolean?
|
32
|
-
@client.sadd?
|
42
|
+
@client.sadd? features_key, feature.key
|
33
43
|
else
|
34
|
-
@client.sadd
|
44
|
+
@client.sadd features_key, feature.key
|
35
45
|
end
|
36
46
|
true
|
37
47
|
end
|
@@ -39,17 +49,17 @@ module Flipper
|
|
39
49
|
# Public: Removes a feature from the set of known features.
|
40
50
|
def remove(feature)
|
41
51
|
if redis_sadd_returns_boolean?
|
42
|
-
@client.srem?
|
52
|
+
@client.srem? features_key, feature.key
|
43
53
|
else
|
44
|
-
@client.srem
|
54
|
+
@client.srem features_key, feature.key
|
45
55
|
end
|
46
|
-
@client.del feature.key
|
56
|
+
@client.del key_for(feature.key)
|
47
57
|
true
|
48
58
|
end
|
49
59
|
|
50
60
|
# Public: Clears the gate values for a feature.
|
51
61
|
def clear(feature)
|
52
|
-
@client.del feature.key
|
62
|
+
@client.del key_for(feature.key)
|
53
63
|
true
|
54
64
|
end
|
55
65
|
|
@@ -78,14 +88,15 @@ module Flipper
|
|
78
88
|
#
|
79
89
|
# Returns true.
|
80
90
|
def enable(feature, gate, thing)
|
91
|
+
feature_key = key_for(feature.key)
|
81
92
|
case gate.data_type
|
82
93
|
when :boolean
|
83
94
|
clear(feature)
|
84
|
-
@client.hset
|
95
|
+
@client.hset feature_key, gate.key, thing.value.to_s
|
85
96
|
when :integer
|
86
|
-
@client.hset
|
97
|
+
@client.hset feature_key, gate.key, thing.value.to_s
|
87
98
|
when :set
|
88
|
-
@client.hset
|
99
|
+
@client.hset feature_key, to_field(gate, thing), 1
|
89
100
|
else
|
90
101
|
unsupported_data_type gate.data_type
|
91
102
|
end
|
@@ -101,13 +112,14 @@ module Flipper
|
|
101
112
|
#
|
102
113
|
# Returns true.
|
103
114
|
def disable(feature, gate, thing)
|
115
|
+
feature_key = key_for(feature.key)
|
104
116
|
case gate.data_type
|
105
117
|
when :boolean
|
106
|
-
@client.del
|
118
|
+
@client.del feature_key
|
107
119
|
when :integer
|
108
|
-
@client.hset
|
120
|
+
@client.hset feature_key, gate.key, thing.value.to_s
|
109
121
|
when :set
|
110
|
-
@client.hdel
|
122
|
+
@client.hdel feature_key, to_field(gate, thing)
|
111
123
|
else
|
112
124
|
unsupported_data_type gate.data_type
|
113
125
|
end
|
@@ -131,14 +143,14 @@ module Flipper
|
|
131
143
|
end
|
132
144
|
|
133
145
|
def read_feature_keys
|
134
|
-
@client.smembers(
|
146
|
+
@client.smembers(features_key).to_set
|
135
147
|
end
|
136
148
|
|
137
149
|
# Private: Gets a hash of fields => values for the given feature.
|
138
150
|
#
|
139
151
|
# Returns a Hash of fields => values.
|
140
152
|
def doc_for(feature, pipeline: @client)
|
141
|
-
pipeline.hgetall(feature.key)
|
153
|
+
pipeline.hgetall(key_for(feature.key))
|
142
154
|
end
|
143
155
|
|
144
156
|
def docs_for(features)
|
data/lib/flipper/version.rb
CHANGED
@@ -28,4 +28,28 @@ RSpec.describe Flipper::Adapters::Redis do
|
|
28
28
|
|
29
29
|
expect(Flipper.adapter.adapter).to be_a(Flipper::Adapters::Redis)
|
30
30
|
end
|
31
|
+
|
32
|
+
describe 'with a key_prefix' do
|
33
|
+
let(:subject) { described_class.new(client, key_prefix: "lockbox:") }
|
34
|
+
let(:feature) { Flipper::Feature.new(:search, subject) }
|
35
|
+
|
36
|
+
it_should_behave_like 'a flipper adapter'
|
37
|
+
|
38
|
+
it 'namespaces feature-keys' do
|
39
|
+
subject.add(feature)
|
40
|
+
|
41
|
+
expect(client.smembers("flipper_features")).to eq([])
|
42
|
+
expect(client.exists?("search")).to eq(false)
|
43
|
+
expect(client.smembers("lockbox:flipper_features")).to eq(["search"])
|
44
|
+
expect(client.hgetall("lockbox:search")).not_to eq(nil)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "can remove namespaced keys" do
|
48
|
+
subject.add(feature)
|
49
|
+
expect(client.smembers("lockbox:flipper_features")).to eq(["search"])
|
50
|
+
|
51
|
+
subject.remove(feature)
|
52
|
+
expect(client.smembers("lockbox:flipper_features")).to be_empty
|
53
|
+
end
|
54
|
+
end
|
31
55
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flipper-redis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.28.
|
4
|
+
version: 0.28.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Nunemaker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: flipper
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.28.
|
19
|
+
version: 0.28.2
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.28.
|
26
|
+
version: 0.28.2
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: redis
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|