Class: Toggleable::RedisStore
- Inherits:
-
StorageAbstract
- Object
- StorageAbstract
- Toggleable::RedisStore
- Defined in:
- lib/toggleable/storage/redis_store.rb
Overview
Toggleable::RedisStore is storage implementation using redis, you should specify namespace to use it. Also pass the redis instance used in when initializing.
Instance Attribute Summary collapse
-
#storage ⇒ Object
Returns the value of attribute storage.
Instance Method Summary collapse
- #get(key, namespace:) ⇒ Object
- #get_all(namespace:) ⇒ Object
-
#initialize(redis_instance) ⇒ RedisStore
constructor
A new instance of RedisStore.
- #mass_set(mappings, namespace:) ⇒ Object
- #set(key, value, namespace:) ⇒ Object
- #set_if_not_exist(key, value, namespace:) ⇒ Object
Constructor Details
#initialize(redis_instance) ⇒ RedisStore
Returns a new instance of RedisStore.
11 12 13 |
# File 'lib/toggleable/storage/redis_store.rb', line 11 def initialize(redis_instance) @storage = redis_instance end |
Instance Attribute Details
#storage ⇒ Object
Returns the value of attribute storage.
9 10 11 |
# File 'lib/toggleable/storage/redis_store.rb', line 9 def storage @storage end |
Instance Method Details
#get(key, namespace:) ⇒ Object
15 16 17 |
# File 'lib/toggleable/storage/redis_store.rb', line 15 def get(key, namespace:) storage.hget(namespace, key) end |
#get_all(namespace:) ⇒ Object
19 20 21 |
# File 'lib/toggleable/storage/redis_store.rb', line 19 def get_all(namespace:) storage.hgetall(namespace) end |
#mass_set(mappings, namespace:) ⇒ Object
31 32 33 34 |
# File 'lib/toggleable/storage/redis_store.rb', line 31 def mass_set(mappings, namespace:) mappings = mappings.flatten if mappings.is_a? Hash storage.hmset(namespace, mappings) end |
#set(key, value, namespace:) ⇒ Object
23 24 25 |
# File 'lib/toggleable/storage/redis_store.rb', line 23 def set(key, value, namespace:) storage.hset(namespace, key, value) end |
#set_if_not_exist(key, value, namespace:) ⇒ Object
27 28 29 |
# File 'lib/toggleable/storage/redis_store.rb', line 27 def set_if_not_exist(key, value, namespace:) storage.hsetnx(namespace, key, value) end |