Created
April 6, 2016 23:22
-
-
Save jakeonrails/9d3e3656fb54df2c9e3f49c411793a43 to your computer and use it in GitHub Desktop.
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
class RingBuffer | |
def initialize(redis=nil, list_key=nil) | |
@redis = redis | |
end | |
def next | |
JSON(@redis.rpoplpush(@list_key, @list_key))[0] | |
end | |
def add(item) | |
@redis.lpush(@list_key, [item].to_json) | |
end | |
def remove(item) | |
@redis.lrem(@list_key, 0, [item].to_json) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment