From 95274f1f8a3ef4cb4033beecfaa99ea1439ed170 Mon Sep 17 00:00:00 2001 From: Leibale Eidelman Date: Tue, 29 Jun 2021 09:38:10 -0400 Subject: [PATCH] fix ZRANGESTORE - should return 0 when src points to an empty key (#9089) mistakenly it used to return an empty array rather than 0. Co-authored-by: Oran Agra --- src/t_zset.c | 7 ++++++- tests/unit/type/zset.tcl | 13 +++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/t_zset.c b/src/t_zset.c index a8ba1342e..51a14989d 100644 --- a/src/t_zset.c +++ b/src/t_zset.c @@ -3660,7 +3660,12 @@ void zrangeGenericCommand(zrange_result_handler *handler, int argc_start, int st lookupKeyWrite(c->db,key) : lookupKeyRead(c->db,key); if (zobj == NULL) { - addReply(c,shared.emptyarray); + if (store) { + handler->beginResultEmission(handler); + handler->finalizeResultEmission(handler, 0); + } else { + addReply(c, shared.emptyarray); + } goto cleanup; } diff --git a/tests/unit/type/zset.tcl b/tests/unit/type/zset.tcl index 838db60d3..e1e7e7882 100644 --- a/tests/unit/type/zset.tcl +++ b/tests/unit/type/zset.tcl @@ -1604,6 +1604,19 @@ start_server {tags {"zset"}} { r zrange z1{t} 5 0 BYSCORE REV LIMIT 0 2 WITHSCORES } {d 4 c 3} + test {ZRANGESTORE - src key missing} { + set res [r zrangestore z2{t} missing{t} 0 -1] + assert_equal $res 0 + r exists z2{t} + } {0} + + test {ZRANGESTORE - src key wrong type} { + r zadd z2{t} 1 a + r set foo{t} bar + assert_error "*WRONGTYPE*" {r zrangestore z2{t} foo{t} 0 -1} + r zrange z2{t} 0 -1 + } {a} + test {ZRANGESTORE - empty range} { set res [r zrangestore z2{t} z1{t} 5 6] assert_equal $res 0