flipper-redis 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d75794c8cf100a5df75ec07ec97123cda83eb195ee7eab7d91b58b1aab04354e
4
- data.tar.gz: 78ae668ed8767209136cfe09d05e8c6a67fc3e7bc9466f4a5637403a99c43706
3
+ metadata.gz: cef5d8c3766ffc4fbaf2dcf79349035b859bd391ccfa87e08086883ddbbcb005
4
+ data.tar.gz: 24984f0ff0baa968662b53b8e7e47288a2597d76f995b7907d19491e4faec447
5
5
  SHA512:
6
- metadata.gz: 513f65a411e1be74144e3870e3149724a78c5ce25692122f85657f50b149b95715473e01b5f423d74edec58d141fe45235246dbf206354b7747d9ad3bfecfd62
7
- data.tar.gz: f1a5a543226d2d0fd55c2c817207541ded0bb09f49e152ca5bb40fbf0069c6e2d9a9d0c9cee0a1b4903177cdbc50f9fb2841e8b778dcc8e98d877792760d447a
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(FeaturesKey)
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(FeaturesKey)
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(GetAllKey, Time.now.to_i)
75
- @cache.expire(GetAllKey, @ttl)
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 FeaturesKey, response.keys.to_set
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
- self.class.key_for(key)
96
+ "#{@namespace}/feature/#{key}"
106
97
  end
107
98
 
108
99
  def read_feature_keys
109
- fetch(FeaturesKey) { @adapter.features }
100
+ fetch(@features_key) { @adapter.features }
110
101
  end
111
102
 
112
103
  def read_many_features(features)
@@ -1,3 +1,3 @@
1
1
  module Flipper
2
- VERSION = '1.0.0'.freeze
2
+ VERSION = '1.1.0'.freeze
3
3
  end
@@ -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(described_class.key_for(feature))).to be(nil)
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(described_class.key_for(stats))).not_to be_nil
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(described_class.key_for(search))).to be(nil)
56
- expect(client.get(described_class.key_for(other))).to be(nil)
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(described_class.key_for(f)))
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(described_class.key_for(stats.key)))[:boolean]).to eq('true')
84
- expect(Marshal.load(client.get(described_class.key_for(search.key)))[:boolean]).to be(nil)
85
- expect(client.get(described_class::GetAllKey).to_i).to be_within(2).of(Time.now.to_i)
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.0.0
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-23 00:00:00.000000000 Z
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.0.0
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.0.0
26
+ version: 1.1.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: redis
29
29
  requirement: !ruby/object:Gem::Requirement