Skip to content

Instantly share code, notes, and snippets.

Created January 17, 2010 23:39
Show Gist options
  • Save anonymous/279658 to your computer and use it in GitHub Desktop.
Save anonymous/279658 to your computer and use it in GitHub Desktop.
require 'redis'
class Set
def initialize(*elems)
@redis = Redis.new
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