Class: TallyJobs::CounterStore::RedisCounterStore

Inherits:
Base
  • Object
show all
Defined in:
lib/tally_jobs/counter_store/redis_counter_store.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#redisObject (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

#clearObject



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

Returns:

  • (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