mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-22 16:18:28 -05:00
fix behavior for out-of-range negative end index on ZREMRANGEBYRANK
This commit is contained in:
parent
184d74abc6
commit
4774a53b24
4
redis.c
4
redis.c
@ -6409,9 +6409,9 @@ static void zremrangebyrankCommand(redisClient *c) {
|
||||
if (start < 0) start = llen+start;
|
||||
if (end < 0) end = llen+end;
|
||||
if (start < 0) start = 0;
|
||||
if (end < 0) end = 0;
|
||||
|
||||
/* indexes sanity checks */
|
||||
/* Invariant: start >= 0, so this test will be true when end < 0.
|
||||
* The range is empty when start > end or start >= length. */
|
||||
if (start > end || start >= llen) {
|
||||
addReply(c,shared.czero);
|
||||
return;
|
||||
|
@ -1,4 +1,11 @@
|
||||
start_server {tags {"zset"}} {
|
||||
proc create_zset {key items} {
|
||||
r del $key
|
||||
foreach {score entry} $items {
|
||||
r zadd $key $score $entry
|
||||
}
|
||||
}
|
||||
|
||||
test {ZSET basic ZADD and score update} {
|
||||
r zadd ztmp 10 x
|
||||
r zadd ztmp 20 y
|
||||
@ -339,15 +346,32 @@ start_server {tags {"zset"}} {
|
||||
list [r zremrangebyscore zset -inf +inf] [r zrange zset 0 -1]
|
||||
} {5 {}}
|
||||
|
||||
test {ZREMRANGEBYRANK basics} {
|
||||
r del zset
|
||||
r zadd zset 1 a
|
||||
r zadd zset 2 b
|
||||
r zadd zset 3 c
|
||||
r zadd zset 4 d
|
||||
r zadd zset 5 e
|
||||
list [r zremrangebyrank zset 1 3] [r zrange zset 0 -1]
|
||||
} {3 {a e}}
|
||||
test "ZREMRANGEBYRANK basics" {
|
||||
proc remrangebyrank {min max} {
|
||||
create_zset zset {1 a 2 b 3 c 4 d 5 e}
|
||||
r zremrangebyrank zset $min $max
|
||||
}
|
||||
|
||||
# inner range
|
||||
assert_equal 3 [remrangebyrank 1 3]
|
||||
assert_equal {a e} [r zrange zset 0 -1]
|
||||
|
||||
# start underflow
|
||||
assert_equal 1 [remrangebyrank -10 0]
|
||||
assert_equal {b c d e} [r zrange zset 0 -1]
|
||||
|
||||
# start overflow
|
||||
assert_equal 0 [remrangebyrank 10 -1]
|
||||
assert_equal {a b c d e} [r zrange zset 0 -1]
|
||||
|
||||
# end underflow
|
||||
assert_equal 0 [remrangebyrank 0 -10]
|
||||
assert_equal {a b c d e} [r zrange zset 0 -1]
|
||||
|
||||
# end overflow
|
||||
assert_equal 5 [remrangebyrank 0 10]
|
||||
assert_equal {} [r zrange zset 0 -1]
|
||||
}
|
||||
|
||||
test {ZUNIONSTORE against non-existing key doesn't set destination} {
|
||||
r del zseta
|
||||
|
Loading…
Reference in New Issue
Block a user