You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kvrocks.apache.org by hu...@apache.org on 2023/07/06 12:00:43 UTC
[kvrocks] branch unstable updated: LSET return no suck key instread of NotFound when key not exist (#1557)
This is an automated email from the ASF dual-hosted git repository.
hulk pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/kvrocks.git
The following commit(s) were added to refs/heads/unstable by this push:
new 80913bc7 LSET return no suck key instread of NotFound when key not exist (#1557)
80913bc7 is described below
commit 80913bc7712db8a0c06c03246e363d4747f835a2
Author: Binbin <bi...@qq.com>
AuthorDate: Thu Jul 6 20:00:37 2023 +0800
LSET return no suck key instread of NotFound when key not exist (#1557)
The current code directly returns s.ToString() in
this case:
```
127.0.0.1:6666> lset nokey 0 1
(error) ERR NotFound:
```
NotFound might not be that friendly, and there's an
extra `:` after it. Modify it to return no such key:
```
127.0.0.1:6666> lset nokey 0 1
(error) ERR no such key
```
Note Redis also return the no such key error in this
case, so it should be fine to return this error.
---
src/commands/cmd_list.cc | 6 +++++-
tests/gocase/unit/type/list/list_test.go | 2 +-
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/src/commands/cmd_list.cc b/src/commands/cmd_list.cc
index f4ccba35..eae93ee0 100644
--- a/src/commands/cmd_list.cc
+++ b/src/commands/cmd_list.cc
@@ -458,10 +458,14 @@ class CommandLSet : public Commander {
Status Execute(Server *svr, Connection *conn, std::string *output) override {
redis::List list_db(svr->storage, conn->GetNamespace());
auto s = list_db.Set(args_[1], index_, args_[3]);
- if (!s.ok()) {
+ if (!s.ok() && !s.IsNotFound()) {
return {Status::RedisExecErr, s.ToString()};
}
+ if (s.IsNotFound()) {
+ return {Status::RedisExecErr, errNoSuchKey};
+ }
+
*output = redis::SimpleString("OK");
return Status::OK();
}
diff --git a/tests/gocase/unit/type/list/list_test.go b/tests/gocase/unit/type/list/list_test.go
index b0625ea6..94f06960 100644
--- a/tests/gocase/unit/type/list/list_test.go
+++ b/tests/gocase/unit/type/list/list_test.go
@@ -791,7 +791,7 @@ func TestList(t *testing.T) {
}
t.Run("LSET against non existing key", func(t *testing.T) {
- util.ErrorRegexp(t, rdb.LSet(ctx, "nosuchkey", 10, "foo").Err(), "ERR.*NotFound.*")
+ util.ErrorRegexp(t, rdb.LSet(ctx, "nosuchkey", 10, "foo").Err(), ".*no such key.*")
})
t.Run("LSET against non list value", func(t *testing.T) {