Unverified Commit 39feee8e authored by Binbin's avatar Binbin Committed by GitHub
Browse files

LPOP/RPOP with count against non existing list return null array (#10095)

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.
```
parent 1e25bdf7
...@@ -501,7 +501,7 @@ void popGenericCommand(client *c, int where) { ...@@ -501,7 +501,7 @@ void popGenericCommand(client *c, int where) {
return; return;
} }
robj *o = lookupKeyWriteOrReply(c, c->argv[1], shared.null[c->resp]); robj *o = lookupKeyWriteOrReply(c, c->argv[1], hascount ? shared.nullarray[c->resp]: shared.null[c->resp]);
if (o == NULL || checkType(c, o, OBJ_LIST)) if (o == NULL || checkType(c, o, OBJ_LIST))
return; return;
......
...@@ -496,15 +496,45 @@ start_server { ...@@ -496,15 +496,45 @@ start_server {
assert_error "*ERR*range*" {r lpop forbarqaz -123} assert_error "*ERR*range*" {r lpop forbarqaz -123}
} }
# Make sure we can distinguish between an empty array and a null response proc verify_resp_response {resp response resp2_response resp3_response} {
r readraw 1 if {$resp == 2} {
assert_equal $response $resp2_response
} elseif {$resp == 3} {
assert_equal $response $resp3_response
}
}
test {RPOP/LPOP with the count 0 returns an empty array} { foreach resp {3 2} {
r lpush listcount zero r hello $resp
r lpop listcount 0
} {*0}
r readraw 0 # Make sure we can distinguish between an empty array and a null response
r readraw 1
test "LPOP/RPOP with the count 0 returns an empty array in RESP$resp" {
r lpush listcount zero
assert_equal {*0} [r lpop listcount 0]
assert_equal {*0} [r rpop listcount 0]
}
test "LPOP/RPOP against non existing key in RESP$resp" {
r del non_existing_key
verify_resp_response $resp [r lpop non_existing_key] {$-1} {_}
verify_resp_response $resp [r rpop non_existing_key] {$-1} {_}
}
test "LPOP/RPOP with <count> against non existing key in RESP$resp" {
r del non_existing_key
verify_resp_response $resp [r lpop non_existing_key 0] {*-1} {_}
verify_resp_response $resp [r lpop non_existing_key 1] {*-1} {_}
verify_resp_response $resp [r rpop non_existing_key 0] {*-1} {_}
verify_resp_response $resp [r rpop non_existing_key 1] {*-1} {_}
}
r readraw 0
}
test {Variadic RPUSH/LPUSH} { test {Variadic RPUSH/LPUSH} {
r del mylist r del mylist
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment