Created
May 29, 2014 09:45
-
-
Save nLight/902df12b37b24c46436d to your computer and use it in GitHub Desktop.
Ruby array-like wrapper for redis sets.
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 '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