Skip to content

Instantly share code, notes, and snippets.

@alandipert
Forked from anonymous/redisarray.rb
Created January 17, 2010 23:39
Show Gist options
  • Save alandipert/279659 to your computer and use it in GitHub Desktop.
Save alandipert/279659 to your computer and use it in GitHub Desktop.
require 'redis'
class Set
def initialize(*elems)
if !defined? @@redis
@@redis = Redis.new
end
elems.each do |elem|
@@redis.set_add(object_id, elem)
end
end
def members
@@redis.set_members(object_id)
end
def union(other)
ret = Set.new
@@redis.set_union_store(ret.object_id, object_id, other.object_id)
ret
end
end
a = Set.new(1,2)
b = Set.new(3,4)
puts a.union(b).members #1,2,3,4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment