flipper-redis 1.0.0.pre → 1.1.0
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 +7 -4
- data/lib/flipper/adapters/redis_cache.rb +12 -21
- data/lib/flipper/version.rb +1 -1
- data/spec/flipper/adapters/redis_cache_spec.rb +8 -8
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cef5d8c3766ffc4fbaf2dcf79349035b859bd391ccfa87e08086883ddbbcb005
|
4
|
+
data.tar.gz: 24984f0ff0baa968662b53b8e7e47288a2597d76f995b7907d19491e4faec447
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c4f17c5b1ef32124dca429462638d75f2e589825c227bd83af8006248b53cee87ef88da3fa58e8abd91b8c8858508a69d7d538f1e1419c10e961c4a79394ed1
|
7
|
+
data.tar.gz: d09947d3c470a5e03ae7937c91b4d7ea7899f3a8663a5ec8399d3c5a2e5fdd22156b262a573aaad5c725685ec356d0e29466e6b725afc64044abc8b4197307ba
|
@@ -7,9 +7,6 @@ module Flipper
|
|
7
7
|
class Redis
|
8
8
|
include ::Flipper::Adapter
|
9
9
|
|
10
|
-
# Public: The name of the adapter.
|
11
|
-
attr_reader :name
|
12
|
-
|
13
10
|
attr_reader :key_prefix
|
14
11
|
|
15
12
|
def features_key
|
@@ -27,7 +24,6 @@ module Flipper
|
|
27
24
|
# flipper's Redis keys
|
28
25
|
def initialize(client, key_prefix: nil)
|
29
26
|
@client = client
|
30
|
-
@name = :redis
|
31
27
|
@key_prefix = key_prefix
|
32
28
|
end
|
33
29
|
|
@@ -97,6 +93,8 @@ module Flipper
|
|
97
93
|
@client.hset feature_key, gate.key, thing.value.to_s
|
98
94
|
when :set
|
99
95
|
@client.hset feature_key, to_field(gate, thing), 1
|
96
|
+
when :json
|
97
|
+
@client.hset feature_key, gate.key, Typecast.to_json(thing.value)
|
100
98
|
else
|
101
99
|
unsupported_data_type gate.data_type
|
102
100
|
end
|
@@ -120,6 +118,8 @@ module Flipper
|
|
120
118
|
@client.hset feature_key, gate.key, thing.value.to_s
|
121
119
|
when :set
|
122
120
|
@client.hdel feature_key, to_field(gate, thing)
|
121
|
+
when :json
|
122
|
+
@client.hdel feature_key, gate.key
|
123
123
|
else
|
124
124
|
unsupported_data_type gate.data_type
|
125
125
|
end
|
@@ -172,6 +172,9 @@ module Flipper
|
|
172
172
|
doc[gate.key.to_s]
|
173
173
|
when :set
|
174
174
|
fields_to_gate_value fields, gate
|
175
|
+
when :json
|
176
|
+
value = doc[gate.key.to_s]
|
177
|
+
Typecast.from_json(value)
|
175
178
|
else
|
176
179
|
unsupported_data_type gate.data_type
|
177
180
|
end
|
@@ -8,28 +8,19 @@ module Flipper
|
|
8
8
|
class RedisCache
|
9
9
|
include ::Flipper::Adapter
|
10
10
|
|
11
|
-
Version = 'v1'.freeze
|
12
|
-
Namespace = "flipper/#{Version}".freeze
|
13
|
-
FeaturesKey = "#{Namespace}/features".freeze
|
14
|
-
GetAllKey = "#{Namespace}/get_all".freeze
|
15
|
-
|
16
|
-
# Private
|
17
|
-
def self.key_for(key)
|
18
|
-
"#{Namespace}/feature/#{key}"
|
19
|
-
end
|
20
|
-
|
21
11
|
# Internal
|
22
12
|
attr_reader :cache
|
23
13
|
|
24
|
-
# Public: The name of the adapter.
|
25
|
-
attr_reader :name
|
26
|
-
|
27
14
|
# Public
|
28
15
|
def initialize(adapter, cache, ttl = 3600)
|
29
16
|
@adapter = adapter
|
30
|
-
@name = :redis_cache
|
31
17
|
@cache = cache
|
32
18
|
@ttl = ttl
|
19
|
+
|
20
|
+
@version = 'v1'.freeze
|
21
|
+
@namespace = "flipper/#{@version}".freeze
|
22
|
+
@features_key = "#{@namespace}/features".freeze
|
23
|
+
@get_all_key = "#{@namespace}/get_all".freeze
|
33
24
|
end
|
34
25
|
|
35
26
|
# Public
|
@@ -40,14 +31,14 @@ module Flipper
|
|
40
31
|
# Public
|
41
32
|
def add(feature)
|
42
33
|
result = @adapter.add(feature)
|
43
|
-
@cache.del(
|
34
|
+
@cache.del(@features_key)
|
44
35
|
result
|
45
36
|
end
|
46
37
|
|
47
38
|
# Public
|
48
39
|
def remove(feature)
|
49
40
|
result = @adapter.remove(feature)
|
50
|
-
@cache.del(
|
41
|
+
@cache.del(@features_key)
|
51
42
|
@cache.del(key_for(feature.key))
|
52
43
|
result
|
53
44
|
end
|
@@ -71,13 +62,13 @@ module Flipper
|
|
71
62
|
end
|
72
63
|
|
73
64
|
def get_all
|
74
|
-
if @cache.setnx(
|
75
|
-
@cache.expire(
|
65
|
+
if @cache.setnx(@get_all_key, Time.now.to_i)
|
66
|
+
@cache.expire(@get_all_key, @ttl)
|
76
67
|
response = @adapter.get_all
|
77
68
|
response.each do |key, value|
|
78
69
|
set_with_ttl key_for(key), value
|
79
70
|
end
|
80
|
-
set_with_ttl
|
71
|
+
set_with_ttl @features_key, response.keys.to_set
|
81
72
|
response
|
82
73
|
else
|
83
74
|
features = read_feature_keys.map { |key| Flipper::Feature.new(key, self) }
|
@@ -102,11 +93,11 @@ module Flipper
|
|
102
93
|
private
|
103
94
|
|
104
95
|
def key_for(key)
|
105
|
-
|
96
|
+
"#{@namespace}/feature/#{key}"
|
106
97
|
end
|
107
98
|
|
108
99
|
def read_feature_keys
|
109
|
-
fetch(
|
100
|
+
fetch(@features_key) { @adapter.features }
|
110
101
|
end
|
111
102
|
|
112
103
|
def read_many_features(features)
|
data/lib/flipper/version.rb
CHANGED
@@ -29,7 +29,7 @@ RSpec.describe Flipper::Adapters::RedisCache do
|
|
29
29
|
feature = flipper[:stats]
|
30
30
|
adapter.get(feature)
|
31
31
|
adapter.remove(feature)
|
32
|
-
expect(client.get(
|
32
|
+
expect(client.get("flipper/v1/feature/#{feature.key}")).to be(nil)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -37,7 +37,7 @@ RSpec.describe Flipper::Adapters::RedisCache do
|
|
37
37
|
it 'uses correct cache key' do
|
38
38
|
stats = flipper[:stats]
|
39
39
|
adapter.get(stats)
|
40
|
-
expect(client.get(
|
40
|
+
expect(client.get("flipper/v1/feature/#{stats.key}")).not_to be_nil
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
@@ -52,13 +52,13 @@ RSpec.describe Flipper::Adapters::RedisCache do
|
|
52
52
|
memory_adapter.reset
|
53
53
|
|
54
54
|
adapter.get(stats)
|
55
|
-
expect(client.get(
|
56
|
-
expect(client.get(
|
55
|
+
expect(client.get("flipper/v1/feature/#{search.key}")).to be(nil)
|
56
|
+
expect(client.get("flipper/v1/feature/#{other.key}")).to be(nil)
|
57
57
|
|
58
58
|
adapter.get_multi([stats, search, other])
|
59
59
|
|
60
60
|
search_cache_value, other_cache_value = [search, other].map do |f|
|
61
|
-
Marshal.load(client.get(
|
61
|
+
Marshal.load(client.get("flipper/v1/feature/#{f.key}"))
|
62
62
|
end
|
63
63
|
expect(search_cache_value[:boolean]).to eq('true')
|
64
64
|
expect(other_cache_value[:boolean]).to be(nil)
|
@@ -80,9 +80,9 @@ RSpec.describe Flipper::Adapters::RedisCache do
|
|
80
80
|
|
81
81
|
it 'warms all features' do
|
82
82
|
adapter.get_all
|
83
|
-
expect(Marshal.load(client.get(
|
84
|
-
expect(Marshal.load(client.get(
|
85
|
-
expect(client.get(
|
83
|
+
expect(Marshal.load(client.get("flipper/v1/feature/#{stats.key}"))[:boolean]).to eq('true')
|
84
|
+
expect(Marshal.load(client.get("flipper/v1/feature/#{search.key}"))[:boolean]).to be(nil)
|
85
|
+
expect(client.get("flipper/v1/get_all").to_i).to be_within(2).of(Time.now.to_i)
|
86
86
|
end
|
87
87
|
|
88
88
|
it 'returns same result when already cached' do
|
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: 1.
|
4
|
+
version: 1.1.0
|
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-08
|
11
|
+
date: 2023-12-08 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: 1.
|
19
|
+
version: 1.1.0
|
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: 1.
|
26
|
+
version: 1.1.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: redis
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -68,9 +68,9 @@ licenses:
|
|
68
68
|
metadata:
|
69
69
|
documentation_uri: https://www.flippercloud.io/docs
|
70
70
|
homepage_uri: https://www.flippercloud.io
|
71
|
-
source_code_uri: https://github.com/
|
72
|
-
bug_tracker_uri: https://github.com/
|
73
|
-
changelog_uri: https://github.com/
|
71
|
+
source_code_uri: https://github.com/flippercloud/flipper
|
72
|
+
bug_tracker_uri: https://github.com/flippercloud/flipper/issues
|
73
|
+
changelog_uri: https://github.com/flippercloud/flipper/blob/main/Changelog.md
|
74
74
|
post_install_message:
|
75
75
|
rdoc_options: []
|
76
76
|
require_paths:
|
@@ -82,11 +82,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
82
82
|
version: '0'
|
83
83
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
84
|
requirements:
|
85
|
-
- - "
|
85
|
+
- - ">="
|
86
86
|
- !ruby/object:Gem::Version
|
87
|
-
version:
|
87
|
+
version: '0'
|
88
88
|
requirements: []
|
89
|
-
rubygems_version: 3.
|
89
|
+
rubygems_version: 3.4.10
|
90
90
|
signing_key:
|
91
91
|
specification_version: 4
|
92
92
|
summary: Redis adapter for Flipper
|