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

maplefu 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 a6d8386e Fix  JSON.STRLEN not_exists return null (#2285)
a6d8386e is described below

commit a6d8386ed407f28af4ff8d91fcb358dfd652ccd7
Author: lizhenglei <[email protected]>
AuthorDate: Tue Apr 30 18:52:50 2024 +0800

    Fix  JSON.STRLEN not_exists return null (#2285)
    
    Co-authored-by: 80597928 <[email protected]>
---
 src/commands/cmd_json.cc                 | 5 +++++
 tests/gocase/unit/type/json/json_test.go | 1 +
 2 files changed, 6 insertions(+)

diff --git a/src/commands/cmd_json.cc b/src/commands/cmd_json.cc
index e29bad83..43421399 100644
--- a/src/commands/cmd_json.cc
+++ b/src/commands/cmd_json.cc
@@ -559,6 +559,11 @@ class CommandJsonStrLen : public Commander {
 
     Optionals<uint64_t> results;
     auto s = json.StrLen(args_[1], path, &results);
+    if (s.IsNotFound()) {
+      *output = conn->NilString();
+      return Status::OK();
+    }
+
     if (!s.ok()) return {Status::RedisExecErr, s.ToString()};
 
     *output = OptionalsToString(conn, results);
diff --git a/tests/gocase/unit/type/json/json_test.go 
b/tests/gocase/unit/type/json/json_test.go
index 51785d29..e30635d4 100644
--- a/tests/gocase/unit/type/json/json_test.go
+++ b/tests/gocase/unit/type/json/json_test.go
@@ -180,6 +180,7 @@ func TestJson(t *testing.T) {
                result2 = append(result2, int64(3), int64(5), interface{}(nil))
                require.NoError(t, rdb.Do(ctx, "JSON.SET", "a", "$", 
`{"a":"foo", "nested": {"a": "hello"}, "nested2": {"a": 31}}`).Err())
                require.Equal(t, rdb.Do(ctx, "JSON.STRLEN", "a", "$..a").Val(), 
result2)
+               require.ErrorIs(t, rdb.Do(ctx, "JSON.STRLEN", "not_exists", 
"$").Err(), redis.Nil)
        })
 
        t.Run("Merge basics", func(t *testing.T) {

Reply via email to