Created
August 13, 2011 14:53
-
-
Save JakubOboza/1143922 to your computer and use it in GitHub Desktop.
Redis Que
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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