Class: TallyJobs::CounterStore::RedisCounterStore
- Defined in:
- lib/tally_jobs/counter_store/redis_counter_store.rb
Instance Attribute Summary collapse
-
#redis ⇒ Object
readonly
Returns the value of attribute redis.
Instance Method Summary collapse
- #clear ⇒ Object
- #dequeue(n = 1) ⇒ Object
- #empty? ⇒ Boolean
- #enqueue(job_clazz, *params) ⇒ Object
-
#initialize(redis:) ⇒ RedisCounterStore
constructor
A new instance of RedisCounterStore.
Constructor Details
#initialize(redis:) ⇒ RedisCounterStore
Returns a new instance of RedisCounterStore.
9 10 11 |
# File 'lib/tally_jobs/counter_store/redis_counter_store.rb', line 9 def initialize(redis:) @redis = redis end |
Instance Attribute Details
#redis ⇒ Object (readonly)
Returns the value of attribute redis.
7 8 9 |
# File 'lib/tally_jobs/counter_store/redis_counter_store.rb', line 7 def redis @redis end |
Instance Method Details
#clear ⇒ Object
25 26 27 |
# File 'lib/tally_jobs/counter_store/redis_counter_store.rb', line 25 def clear @redis.del(KEY) end |
#dequeue(n = 1) ⇒ Object
17 18 19 |
# File 'lib/tally_jobs/counter_store/redis_counter_store.rb', line 17 def dequeue(n = 1) Marshal.load(@redis.lpop(KEY)) end |
#empty? ⇒ Boolean
21 22 23 |
# File 'lib/tally_jobs/counter_store/redis_counter_store.rb', line 21 def empty? @redis.llen(KEY).zero? end |
#enqueue(job_clazz, *params) ⇒ Object
13 14 15 |
# File 'lib/tally_jobs/counter_store/redis_counter_store.rb', line 13 def enqueue(job_clazz, *params) @redis.rpush(KEY, Marshal.dump([job_clazz, *params])) end |