Skip to content

Commit

Permalink
Fix output when key is not found in JSON.GET (#1845)
Browse files Browse the repository at this point in the history
  • Loading branch information
PragmaTwice authored Oct 21, 2023
1 parent 012d529 commit 0276f39
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/commands/cmd_json.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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_)));
Expand Down
2 changes: 2 additions & 0 deletions tests/gocase/unit/type/json/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 0276f39

Please sign in to comment.