Class: TrailGuide::Adapters::Participants::Redis::Adapter
- Inherits:
-
Base::Adapter
- Object
- Base::Adapter
- TrailGuide::Adapters::Participants::Redis::Adapter
- Defined in:
- lib/trail_guide/adapters/participants/redis.rb
Instance Attribute Summary collapse
-
#storage_key ⇒ Object
readonly
Returns the value of attribute storage_key.
Attributes inherited from Base::Adapter
Instance Method Summary collapse
- #[](field) ⇒ Object
- #[]=(field, value) ⇒ Object
- #delete(field) ⇒ Object
- #destroy! ⇒ Object
-
#initialize(context, config, key: nil) ⇒ Adapter
constructor
A new instance of Adapter.
- #key?(field) ⇒ Boolean
- #keys ⇒ Object
- #to_h ⇒ Object
Methods inherited from Base::Adapter
Constructor Details
#initialize(context, config, key: nil) ⇒ Adapter
Returns a new instance of Adapter.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/trail_guide/adapters/participants/redis.rb', line 23 def initialize(context, config, key: nil) super(context, config) if key @storage_key = "#{config.namespace}:#{key}" elsif config.lookup if config.lookup.respond_to?(:call) key = config.lookup.call(context) else key = context.send(config.lookup) end @storage_key = "#{config.namespace}:#{key}" else raise ArgumentError, "You must configure a `lookup` proc to use the redis adapter." end end |
Instance Attribute Details
#storage_key ⇒ Object (readonly)
Returns the value of attribute storage_key.
21 22 23 |
# File 'lib/trail_guide/adapters/participants/redis.rb', line 21 def storage_key @storage_key end |
Instance Method Details
#[](field) ⇒ Object
40 41 42 |
# File 'lib/trail_guide/adapters/participants/redis.rb', line 40 def [](field) TrailGuide.redis.hget(storage_key, field.to_s) end |
#[]=(field, value) ⇒ Object
44 45 46 47 |
# File 'lib/trail_guide/adapters/participants/redis.rb', line 44 def []=(field, value) TrailGuide.redis.hset(storage_key, field.to_s, value) TrailGuide.redis.expire(storage_key, config.expiration) if config.expiration end |
#delete(field) ⇒ Object
49 50 51 |
# File 'lib/trail_guide/adapters/participants/redis.rb', line 49 def delete(field) TrailGuide.redis.hdel(storage_key, field.to_s) end |
#destroy! ⇒ Object
53 54 55 |
# File 'lib/trail_guide/adapters/participants/redis.rb', line 53 def destroy! TrailGuide.redis.del(storage_key) end |
#key?(field) ⇒ Boolean
61 62 63 |
# File 'lib/trail_guide/adapters/participants/redis.rb', line 61 def key?(field) TrailGuide.redis.hexists(storage_key, field.to_s) end |
#keys ⇒ Object
57 58 59 |
# File 'lib/trail_guide/adapters/participants/redis.rb', line 57 def keys TrailGuide.redis.hkeys(storage_key) end |
#to_h ⇒ Object
65 66 67 |
# File 'lib/trail_guide/adapters/participants/redis.rb', line 65 def to_h TrailGuide.redis.hgetall(storage_key) end |