Class: AmaLayout::Notifications::RedisStore

Inherits:
AbstractStore show all
Defined in:
lib/ama_layout/notifications/redis_store.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#baseObject

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

#transactionObject



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