Skip to content

Instantly share code, notes, and snippets.

@nLight
Created May 29, 2014 09:45
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 nLight/902df12b37b24c46436d to your computer and use it in GitHub Desktop.
Save nLight/902df12b37b24c46436d to your computer and use it in GitHub Desktop.
Ruby array-like wrapper for redis sets.
require 'forwardable'
class RedisSet
extend Forwardable
def_delegators :to_ary, :first, :push, :shift, :size, :each, :map
def initialize(redis, key)
@redis = redis
@key = key
end
def << *vals
@redis.sadd @key, *vals
end
def clear
@redis.del @key
end
def delete(*vals)
@redis.srem @key, *vals
end
def to_ary
@redis.smembers @key
end
def size
@redis.scard @key
end
def count
@redis.scard @key
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment