Class: DRbQueue::Store::Redis

Inherits:
DRbQueue::Store show all
Defined in:
lib/drb_queue/store/redis.rb

Constant Summary

Constants inherited from DRbQueue::Store

NotImplementedError

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Redis

Returns a new instance of Redis.



7
8
9
# File 'lib/drb_queue/store/redis.rb', line 7

def initialize(options = {})
  @redis = ::Redis::Namespace.new(:DRbQueue, :redis => options.fetch(:redis, lambda { ::Redis.new }).call)
end

Instance Method Details

#each_persisted_workObject



15
16
17
18
19
20
21
# File 'lib/drb_queue/store/redis.rb', line 15

def each_persisted_work
  return enum_for(:each_persisted_work) unless block_given?

  while serialized_work = redis.lpop(persistence_key)
    yield(serialized_work)
  end
end

#persist(work) ⇒ Object



11
12
13
# File 'lib/drb_queue/store/redis.rb', line 11

def persist(work)
  redis.rpush(persistence_key, work.serialize)
end