Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'rubygems'
- require 'redis'
- $redis = Redis.new()
- $redis.select(3)
- # do a zdiffstore only on scores that match
- # ie [23:12345] will only be removed by [23:12345], not [23:12350]
- def zdiffstore(x, y)
- $redis.zunionstore "tmp.zu", [x, y], :weights=>[1,-1], :aggregate=>:sum
- $redis.zremrangebyscore("tmp.zu", "0", "+inf")
- $redis.zinterstore "o", ["tmp.zu", y], :weights=>[1,1], :aggregate=>:max
- x = $redis.zrange "o", 0, -1, :with_scores => true
- return Hash[*x.flatten]
- end
- # do a zdiffstore ignoring scores that differ
- # ie [23:12345] will be removed by [23:12350]
- def zdiffstore_justkeys(x, y)
- $redis.zunionstore "tmp.zu", [x, y], :weights=>['-inf',1], :aggregate=>:sum
- $redis.zremrangebyscore("tmp.zu", "-inf", "0")
- $redis.zinterstore "o", ["tmp.zu", y], :weights=>[1,1], :aggregate=>:max
- x = $redis.zrange "o", 0, -1, :with_scores => true
- return Hash[*x.flatten]
- end
- a = zdiffstore("user:rjp:read", "all:messages")
- p a.size
Add Comment
Please, Sign In to add comment