Single command for crossing redis, sorted by ranges

Redis:

redis>zadd zsetA 1 'A' redis>zadd zsetA 2 'B' redis>zadd zsetA 3 'C' redis>zadd zsetA 5 'E' redis>zadd zsetB 1 'A' redis>zadd zsetB 2 'B' redis>zadd zsetB 3 'C' redis>zadd zsetB 4 'D' 

opearate:

 a=redis.ZRANGEBYSCORE 'zsetA',1,3 b=redis.ZRANGEBYSCORE 'zsetB',2,4 result=a∩b 

how to quickly get the "result" in the sigle command?

+4
source share
1 answer

I think you are looking for ZINTERSTORE ( http://redis.io/commands/zinterstore ).

Using your example above, it will be something like:

redis.ZINTERSTORE result, 2, 'zsetA', 'zsetB'

And the result will be available by running redis.ZRANGE result, 0, -1

0
source

All Articles