Class: DolphinRedis::RedisFeatureStore

Inherits:
Object
  • Object
show all
Defined in:
lib/dolphin_redis/redis_feature_store.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(redis_opts = {}) ⇒ RedisFeatureStore

Returns a new instance of RedisFeatureStore



6
7
8
9
# File 'lib/dolphin_redis/redis_feature_store.rb', line 6

def initialize(redis_opts = {})
  @redis = Redis.new(redis_opts)
  @store_key = redis_opts[:store_key] || "dolphin_features"
end

Instance Attribute Details

#redisObject (readonly)

Returns the value of attribute redis



11
12
13
# File 'lib/dolphin_redis/redis_feature_store.rb', line 11

def redis
  @redis
end

#store_keyObject (readonly)

Returns the value of attribute store_key



11
12
13
# File 'lib/dolphin_redis/redis_feature_store.rb', line 11

def store_key
  @store_key
end

Instance Method Details

#[](feature_name) ⇒ Object



13
14
15
16
17
# File 'lib/dolphin_redis/redis_feature_store.rb', line 13

def [](feature_name)
  redis.hget(store_key, feature_name.to_s)
rescue  
  'disabled'
end

#clearObject



33
34
35
# File 'lib/dolphin_redis/redis_feature_store.rb', line 33

def clear
  redis.del(store_key)
end

#delete_feature(feature_name) ⇒ Object



29
30
31
# File 'lib/dolphin_redis/redis_feature_store.rb', line 29

def delete_feature(feature_name)
  redis.hdel(store_key, feature_name)
end

#featuresObject



19
20
21
22
23
# File 'lib/dolphin_redis/redis_feature_store.rb', line 19

def features
  redis.hgetall(store_key)
rescue  
  {}
end

#update_feature(feature, flipper) ⇒ Object



25
26
27
# File 'lib/dolphin_redis/redis_feature_store.rb', line 25

def update_feature(feature, flipper)
  redis.hset(store_key, feature.to_s, flipper.to_s)
end