summaryrefslogtreecommitdiff
path: root/src/blocked.c
diff options
context:
space:
mode:
authorBinbin <binloveplay1314@qq.com>2021-11-18 16:13:16 +0800
committerGitHub <noreply@github.com>2021-11-18 10:13:16 +0200
commit91e77a0cfb5c7e4bc6473ae04353e48ad9e8697b (patch)
tree1c97446e9c788eaa0789fa26c645d4523ed0e149 /src/blocked.c
parent32215e788955acd7845d3839ba1f78e137ca0dfb (diff)
downloadredis-91e77a0cfb5c7e4bc6473ae04353e48ad9e8697b.tar.gz
Fixes ZPOPMIN/ZPOPMAX wrong replies when count is 0 with non-zset (#9711)
Moves ZPOP ... 0 fast exit path after type check to reply with WRONGTYPE. In the past it will return an empty array. Also now count is not allowed to be negative. see #9680 before: ``` 127.0.0.1:6379> set zset str OK 127.0.0.1:6379> zpopmin zset 0 (empty array) 127.0.0.1:6379> zpopmin zset -1 (empty array) ``` after: ``` 127.0.0.1:6379> set zset str OK 127.0.0.1:6379> zpopmin zset 0 (error) WRONGTYPE Operation against a key holding the wrong kind of value 127.0.0.1:6379> zpopmin zset -1 (error) ERR value is out of range, must be positive ```
Diffstat (limited to 'src/blocked.c')
-rw-r--r--src/blocked.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/blocked.c b/src/blocked.c
index 8a2e41463..3723b4fbf 100644
--- a/src/blocked.c
+++ b/src/blocked.c
@@ -363,7 +363,7 @@ void serveClientsBlockedOnSortedSetKey(robj *o, readyList *rl) {
argv[0] = where == ZSET_MIN ? shared.zpopmin : shared.zpopmax;
argv[1] = rl->key;
incrRefCount(rl->key);
- if (count != 0) {
+ if (count != -1) {
/* Replicate it as command with COUNT. */
robj *count_obj = createStringObjectFromLongLong((count > llen) ? llen : count);
argv[2] = count_obj;
@@ -371,7 +371,7 @@ void serveClientsBlockedOnSortedSetKey(robj *o, readyList *rl) {
}
propagate(receiver->db->id, argv, argc, PROPAGATE_AOF|PROPAGATE_REPL);
decrRefCount(argv[1]);
- if (count != 0) decrRefCount(argv[2]);
+ if (count != -1) decrRefCount(argv[2]);
/* The zset is empty and has been deleted. */
if (deleted) break;