Skip to content

Instantly share code, notes, and snippets.

@sirupsen
Created September 15, 2013 15:59
Show Gist options
  • Save sirupsen/6571991 to your computer and use it in GitHub Desktop.
Save sirupsen/6571991 to your computer and use it in GitHub Desktop.
Wrap Redis queues in an enumerable.
class RedisQueue
include Enumerable
def initialize(queue)
@queue = queue
end
def each(&block)
while element = redis.lpop(@queue)
block.call(*JSON.parse(element))
end
end
def push(task)
redis.rpush(@queue, task)
end
alias_method :<<, :push
private
def redis
BackgroundQueue.redis
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment