From 450c88f368317ae9d2d3d597cf121999660e2934 Mon Sep 17 00:00:00 2001 From: Binbin Date: Mon, 23 May 2022 19:15:54 +0800 Subject: [PATCH] Fix BZMPOP gets unblocked by non-key args and returns them (#10764) This bug was introduced in #9484 (7.0.0). It result that BZMPOP blocked on non-key arguments. Like `bzmpop 0 1 myzset min count 10`, this command will additionally block in these keys (except for the first and the last argument) and can return their values: - 0: timeout value - 1: numkeys value - min: min/max token - count: count token --- src/t_zset.c | 2 +- tests/unit/type/zset.tcl | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/t_zset.c b/src/t_zset.c index 2efa73936..442e70acd 100644 --- a/src/t_zset.c +++ b/src/t_zset.c @@ -4041,7 +4041,7 @@ void blockingGenericZpopCommand(client *c, robj **keys, int numkeys, int where, /* If the keys do not exist we must block */ struct blockPos pos = {where}; - blockForKeys(c,BLOCKED_ZSET,c->argv+1,c->argc-2,count,timeout,NULL,&pos,NULL); + blockForKeys(c,BLOCKED_ZSET,keys,numkeys,count,timeout,NULL,&pos,NULL); } // BZPOPMIN key [key ...] timeout diff --git a/tests/unit/type/zset.tcl b/tests/unit/type/zset.tcl index 6df856e31..999a60d59 100644 --- a/tests/unit/type/zset.tcl +++ b/tests/unit/type/zset.tcl @@ -2065,6 +2065,33 @@ start_server {tags {"zset"}} { close_replication_stream $repl } {} {needs:repl} + test "BZMPOP should not blocks on non key arguments - #10762" { + set rd1 [redis_deferring_client] + set rd2 [redis_deferring_client] + r del myzset myzset2 myzset3 + + $rd1 bzmpop 0 1 myzset min count 10 + wait_for_blocked_clients_count 1 + $rd2 bzmpop 0 2 myzset2 myzset3 max count 10 + wait_for_blocked_clients_count 2 + + # These non-key keys will not unblock the clients. + r zadd 0 100 timeout_value + r zadd 1 200 numkeys_value + r zadd min 300 min_token + r zadd max 400 max_token + r zadd count 500 count_token + r zadd 10 600 count_value + + r zadd myzset 1 zset + r zadd myzset3 1 zset3 + assert_equal {myzset {{zset 1}}} [$rd1 read] + assert_equal {myzset3 {{zset3 1}}} [$rd2 read] + + $rd1 close + $rd2 close + } {0} {cluster:skip} + test {ZSET skiplist order consistency when elements are moved} { set original_max [lindex [r config get zset-max-ziplist-entries] 1] r config set zset-max-ziplist-entries 0