Class: Flipper::Adapters::Redis
- Inherits:
-
Object
- Object
- Flipper::Adapters::Redis
- Includes:
- Flipper::Adapter
- Defined in:
- lib/flipper/adapters/redis.rb
Constant Summary collapse
- FeaturesKey =
Private: The key that stores the set of known features.
:flipper_features
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Public: The name of the adapter.
Instance Method Summary collapse
-
#add(feature) ⇒ Object
Public: Adds a feature to the set of known features.
-
#clear(feature) ⇒ Object
Public: Clears the gate values for a feature.
-
#disable(feature, gate, thing) ⇒ Object
Public: Disables a gate for a given thing.
-
#enable(feature, gate, thing) ⇒ Object
Public: Enables a gate for a given thing.
-
#features ⇒ Object
Public: The set of known features.
-
#get(feature) ⇒ Object
Public: Gets the values for all gates for a given feature.
- #get_all ⇒ Object
- #get_multi(features) ⇒ Object
-
#initialize(client) ⇒ Redis
constructor
Public: Initializes a Redis flipper adapter.
-
#remove(feature) ⇒ Object
Public: Removes a feature from the set of known features.
Constructor Details
#initialize(client) ⇒ Redis
Public: Initializes a Redis flipper adapter.
client - The Redis client to use. Feel free to namespace it.
19 20 21 22 |
# File 'lib/flipper/adapters/redis.rb', line 19 def initialize(client) @client = client @name = :redis end |
Instance Attribute Details
#name ⇒ Object (readonly)
Public: The name of the adapter.
14 15 16 |
# File 'lib/flipper/adapters/redis.rb', line 14 def name @name end |
Instance Method Details
#add(feature) ⇒ Object
Public: Adds a feature to the set of known features.
30 31 32 33 |
# File 'lib/flipper/adapters/redis.rb', line 30 def add(feature) @client.sadd FeaturesKey, feature.key true end |
#clear(feature) ⇒ Object
Public: Clears the gate values for a feature.
45 46 47 48 |
# File 'lib/flipper/adapters/redis.rb', line 45 def clear(feature) @client.del feature.key true end |
#disable(feature, gate, thing) ⇒ Object
Public: Disables a gate for a given thing.
feature - The Flipper::Feature for the gate. gate - The Flipper::Gate to disable. thing - The Flipper::Type being disabled for the gate.
Returns true.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/flipper/adapters/redis.rb', line 94 def disable(feature, gate, thing) case gate.data_type when :boolean @client.del feature.key when :integer @client.hset feature.key, gate.key, thing.value.to_s when :set @client.hdel feature.key, to_field(gate, thing) else unsupported_data_type gate.data_type end true end |
#enable(feature, gate, thing) ⇒ Object
Public: Enables a gate for a given thing.
feature - The Flipper::Feature for the gate. gate - The Flipper::Gate to disable. thing - The Flipper::Type being enabled for the gate.
Returns true.
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/flipper/adapters/redis.rb', line 74 def enable(feature, gate, thing) case gate.data_type when :boolean, :integer @client.hset feature.key, gate.key, thing.value.to_s when :set @client.hset feature.key, to_field(gate, thing), 1 else unsupported_data_type gate.data_type end true end |
#features ⇒ Object
Public: The set of known features.
25 26 27 |
# File 'lib/flipper/adapters/redis.rb', line 25 def features read_feature_keys end |
#get(feature) ⇒ Object
Public: Gets the values for all gates for a given feature.
Returns a Hash of Flipper::Gate#key => value.
53 54 55 56 |
# File 'lib/flipper/adapters/redis.rb', line 53 def get(feature) doc = doc_for(feature) result_for_feature(feature, doc) end |
#get_all ⇒ Object
62 63 64 65 |
# File 'lib/flipper/adapters/redis.rb', line 62 def get_all features = read_feature_keys.map { |key| Flipper::Feature.new(key, self) } read_many_features(features) end |
#get_multi(features) ⇒ Object
58 59 60 |
# File 'lib/flipper/adapters/redis.rb', line 58 def get_multi(features) read_many_features(features) end |
#remove(feature) ⇒ Object
Public: Removes a feature from the set of known features.
36 37 38 39 40 41 42 |
# File 'lib/flipper/adapters/redis.rb', line 36 def remove(feature) @client.multi do @client.srem FeaturesKey, feature.key @client.del feature.key end true end |