Skip to content

Conversation

@enjoy-binbin
Copy link
Contributor

@enjoy-binbin enjoy-binbin commented Jan 10, 2022

It used to return $-1 in RESP2, now we will return *-1.
This is a bug in redis 6.2 when COUNT was added, the COUNT
option was introduced in #8179. Fix #10089.

the documentation of LPOP says

When called without the count argument:
Bulk string reply: the value of the first element, or nil when key does not exist.

When called with the count argument:
Array reply: list of popped elements, or nil when key does not exist.

It used to return `$-1` in RESP2, now we will return `*-1`.
This is a bug in redis 6.2 when COUNT was added, the `COUNT`
option was introduced in redis#8179. Fix redis#10089.
@oranagra oranagra added 7.0-must-have approval-needed Waiting for core team approval to be merged breaking-change This change can potentially break existing application release-notes indication that this issue needs to be mentioned in the release notes state:major-decision Requires core team consensus labels Jan 10, 2022
@oranagra
Copy link
Member

@enjoy-binbin can you scan other places where COUNT was added in 6.2 and other early exists of these commands to see if we don't have similar issues in other places.

@enjoy-binbin
Copy link
Contributor Author

sure, i can take a look tomorrow

Copy link
Contributor

@madolson madolson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to verifying the other locations don't introduce weird changes. We should backport this to 6.2 as well.

@oranagra
Copy link
Member

@madolson it does match 6.0 already.
6.0 didn't have the count argument, so it always returned null string in this case

@madolson
Copy link
Contributor

@oranagra For some reason I thought this broke from 6.0->6.2, but I understand now, it doesn't change my opinion.

@enjoy-binbin
Copy link
Contributor Author

enjoy-binbin commented Jan 11, 2022

base on this branch (this PR)

saying up front, i scanned most of the commands, here is the result:
it looks like we've got everything covered

shared.emptyarray = createObject(OBJ_STRING,sdsnew("*0\r\n"));

shared.null[2] = createObject(OBJ_STRING,sdsnew("$-1\r\n"));
shared.null[3] = createObject(OBJ_STRING,sdsnew("_\r\n"));

shared.nullarray[2] = createObject(OBJ_STRING,sdsnew("*-1\r\n"));
shared.nullarray[3] = createObject(OBJ_STRING,sdsnew("_\r\n"));

shared.emptymap[2] = createObject(OBJ_STRING,sdsnew("*0\r\n"));
shared.emptymap[3] = createObject(OBJ_STRING,sdsnew("%0\r\n"));

shared.emptyset[2] = createObject(OBJ_STRING,sdsnew("*0\r\n"));
shared.emptyset[3] = createObject(OBJ_STRING,sdsnew("~0\r\n"));

list:

LPOP/RPOP key [count] (count added in 6.2)

  • without count:
    • non existing: return shared.null[resp]
  • with count:

set:

SPOP key [count] (count added in 3.2)

  • without count:
    • non existing: return shared.null[c->resp]
  • with count:

SRANDMEMBER


zset:

ZPOPMIN/ZPOPMAX key [count]

  • without count:
    • non existing zset: return shared.emptyarray
  • with count:
    • non existing: return shared.emptyarray
    • count is 0: return shared.emptyarray

ZRANDMEMBER


hash:

HGETALL key
non existing: return shared.emptymap[c->resp] (used to return shared.emptyarray, fixed it in #7781)

HRANDFIELD


geo:

georadius*
geosearch

@oranagra oranagra merged commit 39feee8 into redis:unstable Jan 11, 2022
@enjoy-binbin enjoy-binbin deleted the fix_pop_with_count branch January 11, 2022 12:27
This was referenced Apr 27, 2022
oranagra pushed a commit that referenced this pull request Apr 27, 2022
)

It used to return `$-1` in RESP2, now we will return `*-1`.
This is a bug in redis 6.2 when COUNT was added, the `COUNT`
option was introduced in #8179. Fix #10089.

the documentation of [LPOP](https://redis.io/commands/lpop) says
```
When called without the count argument:
Bulk string reply: the value of the first element, or nil when key does not exist.

When called with the count argument:
Array reply: list of popped elements, or nil when key does not exist.
```

(cherry picked from commit 39feee8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approval-needed Waiting for core team approval to be merged breaking-change This change can potentially break existing application release-notes indication that this issue needs to be mentioned in the release notes state:major-decision Requires core team consensus

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

[BUG] LPOP key [count] returns Null Bulk reply instead of Null array reply.

4 participants