Skip to content

Instantly share code, notes, and snippets.

@jakeonrails
Created April 6, 2016 23:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakeonrails/9d3e3656fb54df2c9e3f49c411793a43 to your computer and use it in GitHub Desktop.
Save jakeonrails/9d3e3656fb54df2c9e3f49c411793a43 to your computer and use it in GitHub Desktop.
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