Class: AmaLayout::Notifications::RedisStore
- Inherits:
-
AbstractStore
- Object
- AbstractStore
- AmaLayout::Notifications::RedisStore
- Defined in:
- lib/ama_layout/notifications/redis_store.rb
Instance Attribute Summary collapse
-
#base ⇒ Object
Returns the value of attribute base.
Instance Method Summary collapse
- #delete(key, opts = {}) ⇒ Object
- #get(key, opts = {}) ⇒ Object
-
#initialize(opts = {}) ⇒ RedisStore
constructor
A new instance of RedisStore.
- #set(key, value, opts = {}) ⇒ Object
- #transaction ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ RedisStore
Returns a new instance of RedisStore.
8 9 10 11 12 13 |
# File 'lib/ama_layout/notifications/redis_store.rb', line 8 def initialize(opts = {}) self.base = ActiveSupport::Cache.lookup_store( :redis_store, opts.merge(raw: true) ) end |
Instance Attribute Details
#base ⇒ Object
Returns the value of attribute base.
6 7 8 |
# File 'lib/ama_layout/notifications/redis_store.rb', line 6 def base @base end |
Instance Method Details
#delete(key, opts = {}) ⇒ Object
27 28 29 |
# File 'lib/ama_layout/notifications/redis_store.rb', line 27 def delete(key, opts = {}) base.delete(key, opts) == 1 end |
#get(key, opts = {}) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/ama_layout/notifications/redis_store.rb', line 15 def get(key, opts = {}) if opts.fetch(:default, false) base.fetch(key) { opts[:default] } else base.read(key) end end |
#set(key, value, opts = {}) ⇒ Object
23 24 25 |
# File 'lib/ama_layout/notifications/redis_store.rb', line 23 def set(key, value, opts = {}) base.write(key, value, opts) == 'OK' end |
#transaction ⇒ Object
31 32 33 34 35 |
# File 'lib/ama_layout/notifications/redis_store.rb', line 31 def transaction base.data.multi do yield self end end |