mirror of
https://github.com/fluencelabs/redis
synced 2025-04-06 17:41:03 +00: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 (start < 0) start = llen+start;
|
||||||
if (end < 0) end = llen+end;
|
if (end < 0) end = llen+end;
|
||||||
if (start < 0) start = 0;
|
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) {
|
if (start > end || start >= llen) {
|
||||||
addReply(c,shared.czero);
|
addReply(c,shared.czero);
|
||||||
return;
|
return;
|
||||||
|
@ -1,4 +1,11 @@
|
|||||||
start_server {tags {"zset"}} {
|
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} {
|
test {ZSET basic ZADD and score update} {
|
||||||
r zadd ztmp 10 x
|
r zadd ztmp 10 x
|
||||||
r zadd ztmp 20 y
|
r zadd ztmp 20 y
|
||||||
@ -339,15 +346,32 @@ start_server {tags {"zset"}} {
|
|||||||
list [r zremrangebyscore zset -inf +inf] [r zrange zset 0 -1]
|
list [r zremrangebyscore zset -inf +inf] [r zrange zset 0 -1]
|
||||||
} {5 {}}
|
} {5 {}}
|
||||||
|
|
||||||
test {ZREMRANGEBYRANK basics} {
|
test "ZREMRANGEBYRANK basics" {
|
||||||
r del zset
|
proc remrangebyrank {min max} {
|
||||||
r zadd zset 1 a
|
create_zset zset {1 a 2 b 3 c 4 d 5 e}
|
||||||
r zadd zset 2 b
|
r zremrangebyrank zset $min $max
|
||||||
r zadd zset 3 c
|
}
|
||||||
r zadd zset 4 d
|
|
||||||
r zadd zset 5 e
|
# inner range
|
||||||
list [r zremrangebyrank zset 1 3] [r zrange zset 0 -1]
|
assert_equal 3 [remrangebyrank 1 3]
|
||||||
} {3 {a e}}
|
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} {
|
test {ZUNIONSTORE against non-existing key doesn't set destination} {
|
||||||
r del zseta
|
r del zseta
|
||||||
|
Loading…
x
Reference in New Issue
Block a user