Long time lurker, first time poster. Does anybody know if there is a
way to use a redis command to intersect a set and a sorted set in
memory on the redis server ?
Thanks,
Paul
--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To post to this group, send email to redi...@googlegroups.com.
To unsubscribe from this group, send email to redis-db+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/redis-db?hl=en.
You can intersect sets and sorted sets via zinterstore (or union them
via zunionstore). Scores for sets are defaulted to 1, but you can
adjust the scores on the entire set by using the weights parameter. I
managed to get that patch in a little over a year ago ;)
Regards,
- Josiah
>>> import redis
>>> c = redis.Redis()
>>> c.sadd('foo', 'bar')
True
>>> c.sadd('foo', 'baz')
True
>>> c.zadd('goo', 'baz', 3)
True
>>> c.zadd('goo', 'boo', 2)
True
>>> c.zinterstore('out', ['foo', 'goo']) # the default aggregate is SUM
1L
>>> c.zrange('out', 0, -1, withscores=True)
[('baz', 4.0)]
>>> c.zunionstore('out', ['foo', 'goo'])
3L
>>> c.zrange('out', 0, -1, withscores=True)
[('bar', 1.0), ('boo', 2.0), ('baz', 4.0)]
>>>
Regards,
- Josiah