Skip to content

Instantly share code, notes, and snippets.

@JakubOboza
Created August 13, 2011 14:53
Show Gist options
  • Save JakubOboza/1143922 to your computer and use it in GitHub Desktop.
Save JakubOboza/1143922 to your computer and use it in GitHub Desktop.
Redis Que
require 'redis'
class RQue
attr_reader :name, :connection
def initialize(name)
@name = name
@connection = Redis.new
end
def push(value)
self.connection.lpush(self.name, value)
end
def pop
self.connection.rpop(self.name)
end
end
que = RQue.new("test")
que.push("http://www.ruby-doc.org")
que.push("http://no-fucking-idea.com")
5.times { puts (que.pop).inspect }
# > "http://www.ruby-doc.org"
# > "http://no-fucking-idea.com"
# > nil
# > nil
# > nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment