lib/flipper/adapters/redis.rb in flipper-redis-1.0.0 vs lib/flipper/adapters/redis.rb in flipper-redis-1.1.0
- old
+ new
@@ -5,13 +5,10 @@
module Flipper
module Adapters
class Redis
include ::Flipper::Adapter
- # Public: The name of the adapter.
- attr_reader :name
-
attr_reader :key_prefix
def features_key
"#{key_prefix}flipper_features"
end
@@ -25,11 +22,10 @@
# client - The Redis client to use.
# key_prefix - an optional prefix with which to namespace
# flipper's Redis keys
def initialize(client, key_prefix: nil)
@client = client
- @name = :redis
@key_prefix = key_prefix
end
# Public: The set of known features.
def features
@@ -95,10 +91,12 @@
@client.hset feature_key, gate.key, thing.value.to_s
when :integer
@client.hset feature_key, gate.key, thing.value.to_s
when :set
@client.hset feature_key, to_field(gate, thing), 1
+ when :json
+ @client.hset feature_key, gate.key, Typecast.to_json(thing.value)
else
unsupported_data_type gate.data_type
end
true
@@ -118,10 +116,12 @@
@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)
+ when :json
+ @client.hdel feature_key, gate.key
else
unsupported_data_type gate.data_type
end
true
@@ -170,9 +170,12 @@
case gate.data_type
when :boolean, :integer
doc[gate.key.to_s]
when :set
fields_to_gate_value fields, gate
+ when :json
+ value = doc[gate.key.to_s]
+ Typecast.from_json(value)
else
unsupported_data_type gate.data_type
end
end