mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-23 00:28:26 -05:00
ZREVRANGEBYSCORE Optimization for out of range offset (#5773)
ZREVRANGEBYSCORE key max min [WITHSCORES] [LIMIT offset count] When the offset is too large, the query is very slow. Especially when the offset is greater than the length of zset it is easy to determine whether the offset is greater than the length of zset at first, and If it exceed the length of zset, then return directly. Co-authored-by: Oran Agra <oran@redislabs.com>
This commit is contained in:
parent
d638b05834
commit
39f716a121
@ -2906,6 +2906,12 @@ void genericZrangebyscoreCommand(client *c, int reverse) {
|
|||||||
if ((zobj = lookupKeyReadOrReply(c,key,shared.emptyarray)) == NULL ||
|
if ((zobj = lookupKeyReadOrReply(c,key,shared.emptyarray)) == NULL ||
|
||||||
checkType(c,zobj,OBJ_ZSET)) return;
|
checkType(c,zobj,OBJ_ZSET)) return;
|
||||||
|
|
||||||
|
/* For invalid offset, return directly. */
|
||||||
|
if (offset > 0 && offset >= (long)zsetLength(zobj)) {
|
||||||
|
addReply(c,shared.emptyarray);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (zobj->encoding == OBJ_ENCODING_ZIPLIST) {
|
if (zobj->encoding == OBJ_ENCODING_ZIPLIST) {
|
||||||
unsigned char *zl = zobj->ptr;
|
unsigned char *zl = zobj->ptr;
|
||||||
unsigned char *eptr, *sptr;
|
unsigned char *eptr, *sptr;
|
||||||
|
@ -432,6 +432,7 @@ start_server {tags {"zset"}} {
|
|||||||
create_default_zset
|
create_default_zset
|
||||||
assert_equal {e 4 f 5} [r zrangebyscore zset 2 5 LIMIT 2 3 WITHSCORES]
|
assert_equal {e 4 f 5} [r zrangebyscore zset 2 5 LIMIT 2 3 WITHSCORES]
|
||||||
assert_equal {d 3 c 2} [r zrevrangebyscore zset 5 2 LIMIT 2 3 WITHSCORES]
|
assert_equal {d 3 c 2} [r zrevrangebyscore zset 5 2 LIMIT 2 3 WITHSCORES]
|
||||||
|
assert_equal {} [r zrangebyscore zset 2 5 LIMIT 12 13 WITHSCORES]
|
||||||
}
|
}
|
||||||
|
|
||||||
test "ZRANGEBYSCORE with non-value min or max" {
|
test "ZRANGEBYSCORE with non-value min or max" {
|
||||||
|
Loading…
Reference in New Issue
Block a user