Skip to content
Browse files

Merge branch 'master' of github.com:kengonakajima/snippets

  • Loading branch information...
2 parents 8842bb6 + c0fc404 commit 17e965ab8674e51b3bba2884967455ce8f04455b @kengonakajima committed Mar 31, 2012
Showing with 33 additions and 0 deletions.
  1. +33 −0 ruby/redis/set.rb
View
33 ruby/redis/set.rb
@@ -0,0 +1,33 @@
+require "rubygems"
+require "redis"
+require "redis/list"
+require "redis/hash_key"
+require "json"
+
+Redis.current = Redis.new( :host=>"localhost", :port=>6379 )
+
+redis = Redis.current
+
+redis.del "settest"
+redis.del "settest2"
+
+redis.sadd "settest", "kome"
+redis.sadd "settest", "tamago"
+redis.sadd "settest", "kome"
+
+print redis.scard( "settest" ), "\n"
+
+redis.sadd "settest2", "banana"
+redis.sadd "settest2", "ringo"
+redis.sadd "settest2", "kome"
+
+out = redis.sinter "settest", "settest2"
+out.each do |x| print("x:",x,"\n")end
+
+print "--\n"
+
+out = redis.sdiff "settest", "settest2"
+out.each do |x| print("x:",x,"\n")end
+
+redis.lpush "settest", "xx" " -> error raised
+

0 comments on commit 17e965a

Please sign in to comment.
Something went wrong with that request. Please try again.