Sha256: 2214c5575d9f4499ea3b1f42054f514d4e749ff31fd967c7f6331fd6d5082534
Contents?: true
Size: 1.21 KB
Versions: 1
Compression:
Stored size: 1.21 KB
Contents
module Blendris # RedisSet is a wrapper to the Redis SET data type. class RedisSet < RedisNode include Enumerable def initialize(key, options = {}) @key = key.to_s @options = options @on_change = options[:on_change] end def each redis.smembers(key).each do |value| yield value end self end def set(*values) self.clear values.flatten.compact.each do |v| redis.sadd key, v end self ensure notify_changed end def <<(value) [ value ].flatten.compact.each do |v| redis.sadd key, v end self ensure notify_changed end def get self end def delete(value) redis.srem key, value ensure notify_changed end def count redis.scard key end # Set this set's members to the intersection of this set and the given set. def intersect!(other) redis.sinterstore key, key, other.key ensure notify_changed end # Set this set's members to the union of this set and the given set. def union!(other) redis.sunionstore key, key, other.key ensure notify_changed end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
blendris-1.2 | lib/blendris/set.rb |