Fix sort_ro get-keys function return wrong key number (#12522)

Before:
```
127.0.0.1:6379> command getkeys sort_ro key
(empty array)
127.0.0.1:6379>
```
After:
```
127.0.0.1:6379> command getkeys sort_ro key
1) "key"
127.0.0.1:6379>
```
This commit is contained in:
bodong.ybd 2023-08-31 03:00:02 +08:00 committed by GitHub
parent e3d4b30d09
commit b59f53efb3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View File

@ -2294,7 +2294,8 @@ int sortROGetKeys(struct redisCommand *cmd, robj **argv, int argc, getKeysResult
keys = getKeysPrepareResult(result, 1);
keys[0].pos = 1; /* <sort-key> is always present. */
keys[0].flags = CMD_KEY_RO | CMD_KEY_ACCESS;
return 1;
result->numkeys = 1;
return result->numkeys;
}
/* Helper function to extract keys from the SORT command.

View File

@ -109,6 +109,10 @@ start_server {
test "SORT extracts STORE correctly" {
r command getkeys sort abc store def
} {abc def}
test "SORT_RO get keys" {
r command getkeys sort_ro abc
} {abc}
test "SORT extracts multiple STORE correctly" {
r command getkeys sort abc store invalid store stillbad store def