djveremix / redis

Automatically exported from code.google.com/p/redis
0 stars 0 forks source link

[patch] ZRANGEBYSCORESTORE #281

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I (as well as others, probably) need a way to store the result of a 
ZRANGEBYSCORE in order to intersect subranges of a ZSET.
As my original [proposal][1] of adding a generic STORE command seems to collide 
with the future of scripting in redis, and given that scripting might take some 
time to come, I added a ZRANGEBYSCORESTORE (sorry for the name…) command.

example use:
----------
compute dudes between 20 and 25 yo who measure more than 170cm

redis> ZADD ages 20 "Joe"
(integer) 1
redis> ZADD ages 24 "John"
(integer) 1
redis> ZADD ages 22 "Jack"
(integer) 1
redis> ZADD ages 28 "Josh"
(integer) 1
redis> ZADD heights 180 "Joe"
(integer) 1
redis> ZADD heights 175 "Josh"
(integer) 1
redis> ZADD heights 165 "John"
(integer) 1
redis> ZADD heights 172 "Jack"
(integer) 1
redis> ZRANGEBYSCORESTORE tmp1 ages 20 25
(integer) 3
redis> ZRANGEBYSCORESTORE tmp2 heights 170 +inf
(integer) 3
redis> ZINTERSTORE result 2 tmp1 tmp2
(integer) 2
redis> ZRANGE result 0 -1
1. "Jack"
2. "Joe"

[1]: http://code.google.com/p/redis/issues/detail?id=280

Original issue reported on code.google.com by adrien.friggeri on 15 Jul 2010 at 4:53

GoogleCodeExporter commented 8 years ago
I was pretty sure I had attached the patch… Must have forgotten…
Fixed.

Original comment by adrien.friggeri on 15 Jul 2010 at 5:42

Attachments:

GoogleCodeExporter commented 8 years ago
Adrien,

Are you planning to update the patch to be compatible with the 2.2 release?

Thanks.

Original comment by alexis.s...@gmail.com on 13 Feb 2011 at 11:38

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
There is an alternative way already supported by Redis 2.2.2

For each zset, duplicate it (for working on it) and delete the keys in the 
duplicated set which are not in the required range (using ZREMRANGEBYSCORE).

Then just intersect the zsets using ZINTERSTORE.

Original comment by nilo.tei...@gmail.com on 1 Apr 2011 at 7:58