Class: Bandit::DalliStorage
- Inherits:
-
BaseStorage
- Object
- BaseStorage
- Bandit::DalliStorage
- Defined in:
- lib/bandit/storage/dalli.rb
Instance Method Summary collapse
- #clear! ⇒ Object
-
#get(key, default = 0) ⇒ Object
get key if exists, otherwise 0.
-
#incr(key, count = 1) ⇒ Object
increment key by count.
-
#init(key, value) ⇒ Object
initialize key if not set.
-
#initialize(config) ⇒ DalliStorage
constructor
A new instance of DalliStorage.
-
#set(key, value) ⇒ Object
set key with value, regardless of whether it is set or not.
Methods inherited from BaseStorage
#alt_started_key, #alternative_start_time, #conv_key, #conversion_count, get_storage, #incr_conversions, #incr_participants, #make_key, #part_key, #participant_count, #player_state_get, #player_state_key, #player_state_set, #with_failure_grace
Constructor Details
#initialize(config) ⇒ DalliStorage
Returns a new instance of DalliStorage.
3 4 5 6 7 |
# File 'lib/bandit/storage/dalli.rb', line 3 def initialize(config) require 'dalli' config[:namespace] ||= 'bandit' @dalli = Dalli::Client.new(config.fetch(:host, 'localhost:11211'), config) end |
Instance Method Details
#clear! ⇒ Object
38 39 40 41 42 |
# File 'lib/bandit/storage/dalli.rb', line 38 def clear! with_failure_grace(nil) { @dalli.flush_all } end |
#get(key, default = 0) ⇒ Object
get key if exists, otherwise 0
25 26 27 28 29 |
# File 'lib/bandit/storage/dalli.rb', line 25 def get(key, default=0) with_failure_grace(default) { @dalli.get(key) || default } end |
#incr(key, count = 1) ⇒ Object
increment key by count
10 11 12 13 14 15 |
# File 'lib/bandit/storage/dalli.rb', line 10 def incr(key, count=1) # dalli incr is broken just like in memcache-client gem with_failure_grace(count) { set(key, get(key, 0) + count) } end |
#init(key, value) ⇒ Object
initialize key if not set
18 19 20 21 22 |
# File 'lib/bandit/storage/dalli.rb', line 18 def init(key, value) with_failure_grace(value) { @dalli.add(key, value) } end |
#set(key, value) ⇒ Object
set key with value, regardless of whether it is set or not
32 33 34 35 36 |
# File 'lib/bandit/storage/dalli.rb', line 32 def set(key, value) with_failure_grace(value) { @dalli.set(key, value) } end |