summaryrefslogtreecommitdiff
path: root/src/t_zset.c
diff options
context:
space:
mode:
authorBinbin <binloveplay1314@qq.com>2021-10-31 22:10:29 +0800
committerGitHub <noreply@github.com>2021-10-31 16:10:29 +0200
commit033578839be929a5b550e4991c6c6d26e44af3ad (patch)
tree02dcee48c064a840739d74694a4e97ead7a18149 /src/t_zset.c
parent215b909c1fa7d8d2e49e40187380be1be70e1714 (diff)
downloadredis-033578839be929a5b550e4991c6c6d26e44af3ad.tar.gz
Fix multiple COUNT in LMPOP/BLMPOP/ZMPOP/BZMPOP (#9701)
The previous code did not check whether COUNT is set. So we can use `lmpop 2 key1 key2 left count 1 count 2`. This situation can occur in LMPOP/BLMPOP/ZMPOP/BZMPOP commands. LMPOP/BLMPOP introduced in #9373, ZMPOP/BZMPOP introduced in #9484.
Diffstat (limited to 'src/t_zset.c')
-rw-r--r--src/t_zset.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/t_zset.c b/src/t_zset.c
index 157ff84c5..952d24709 100644
--- a/src/t_zset.c
+++ b/src/t_zset.c
@@ -4287,7 +4287,7 @@ void zmpopGenericCommand(client *c, int numkeys_idx, int is_block) {
long j;
long numkeys = 0; /* Number of keys. */
int where = 0; /* ZSET_MIN or ZSET_MAX. */
- long count = 1; /* Reply will consist of up to count elements, depending on the zset's length. */
+ long count = 0; /* Reply will consist of up to count elements, depending on the zset's length. */
/* Parse the numkeys. */
if (getRangeLongFromObjectOrReply(c, c->argv[numkeys_idx], 1, LONG_MAX,
@@ -4314,7 +4314,7 @@ void zmpopGenericCommand(client *c, int numkeys_idx, int is_block) {
char *opt = c->argv[j]->ptr;
int moreargs = (c->argc - 1) - j;
- if (!strcasecmp(opt, "COUNT") && moreargs) {
+ if (count == 0 && !strcasecmp(opt, "COUNT") && moreargs) {
j++;
if (getRangeLongFromObjectOrReply(c, c->argv[j], 1, LONG_MAX,
&count,"count should be greater than 0") != C_OK)
@@ -4325,6 +4325,8 @@ void zmpopGenericCommand(client *c, int numkeys_idx, int is_block) {
}
}
+ if (count == 0) count = 1;
+
if (is_block) {
/* BLOCK. We will handle CLIENT_DENY_BLOCKING flag in blockingGenericZpopCommand. */
blockingGenericZpopCommand(c, c->argv+numkeys_idx+1, numkeys, where, 1, count, 1, 1);