This is an automated email from the ASF dual-hosted git repository.

twice 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 0276f39b Fix output when key is not found in JSON.GET (#1845)
0276f39b is described below

commit 0276f39ba3cd5f531763c3ffca69cce199fe5338
Author: Twice <[email protected]>
AuthorDate: Sat Oct 21 11:32:11 2023 +0900

    Fix output when key is not found in JSON.GET (#1845)
---
 src/commands/cmd_json.cc                 | 4 ++++
 tests/gocase/unit/type/json/json_test.go | 2 ++
 2 files changed, 6 insertions(+)

diff --git a/src/commands/cmd_json.cc b/src/commands/cmd_json.cc
index 0d5e6aae..1a014d28 100644
--- a/src/commands/cmd_json.cc
+++ b/src/commands/cmd_json.cc
@@ -82,6 +82,10 @@ class CommandJsonGet : public Commander {
 
     JsonValue result;
     auto s = json.Get(args_[1], paths_, &result);
+    if (s.IsNotFound()) {
+      *output = redis::NilString();
+      return Status::OK();
+    }
     if (!s.ok()) return {Status::RedisExecErr, s.ToString()};
 
     *output = redis::BulkString(GET_OR_RET(result.Print(indent_size_, 
spaces_after_colon_, new_line_chars_)));
diff --git a/tests/gocase/unit/type/json/json_test.go 
b/tests/gocase/unit/type/json/json_test.go
index 14ac3372..fe6a8787 100644
--- a/tests/gocase/unit/type/json/json_test.go
+++ b/tests/gocase/unit/type/json/json_test.go
@@ -54,6 +54,8 @@ func TestJson(t *testing.T) {
                require.Equal(t, rdb.Do(ctx, "JSON.GET", "a", "$").Val(), 
`[{"x":1,"y":{"x":{"y":2},"y":3}}]`)
                require.Equal(t, rdb.Do(ctx, "JSON.GET", "a", "$..x").Val(), 
`[1,{"y":2}]`)
                require.Equal(t, rdb.Do(ctx, "JSON.GET", "a", "$..x", 
"$..y").Val(), `{"$..x":[1,{"y":2}],"$..y":[{"x":{"y":2},"y":3},3,2]}`)
+
+               require.Equal(t, rdb.Do(ctx, "JSON.GET", "no-such-key").Val(), 
nil)
        })
 
        t.Run("JSON.GET with options", func(t *testing.T) {

Reply via email to