Skip to content

Commit

Permalink
Add the support of JSON.FORGET command (#1917)
Browse files Browse the repository at this point in the history
  • Loading branch information
git-hulk authored Dec 3, 2023
1 parent 55d21dd commit d2312a4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/commands/cmd_json.cc
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,8 @@ REDIS_REGISTER_COMMANDS(MakeCmdAttr<CommandJsonSet>("json.set", 4, "write", 1, 1
MakeCmdAttr<CommandJsonArrPop>("json.arrpop", -2, "write", 1, 1, 1),
MakeCmdAttr<CommanderJsonArrIndex>("json.arrindex", -4, "read-only", 1, 1, 1),
MakeCmdAttr<CommandJsonDel>("json.del", -2, "write", 1, 1, 1),
// JSON.FORGET is an alias for JSON.DEL, refer: https://redis.io/commands/json.forget/
MakeCmdAttr<CommandJsonDel>("json.forget", -2, "write", 1, 1, 1),
MakeCmdAttr<CommandJsonNumIncrBy>("json.numincrby", 4, "write", 1, 1, 1),
MakeCmdAttr<CommandJsonNumMultBy>("json.nummultby", 4, "write", 1, 1, 1), );

Expand Down
13 changes: 13 additions & 0 deletions tests/gocase/unit/type/json/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ func TestJson(t *testing.T) {
require.Equal(t, rdb.Type(ctx, "a").Val(), "ReJSON-RL")
})

t.Run("JSON.DEL and JSON.FORGET basics", func(t *testing.T) {
// JSON.DEL and JSON.FORGET are aliases
for _, command := range []string{"JSON.DEL", "JSON.FORGET"} {
require.NoError(t, rdb.Do(ctx, "JSON.SET", "a", "$", `{"x": 1, "nested": {"x": 2, "y": 3}}`).Err())
require.EqualValues(t, 2, rdb.Do(ctx, command, "a", "$..x").Val())
require.Equal(t, `[{"nested":{"y":3}}]`, rdb.Do(ctx, "JSON.GET", "a", "$").Val())

require.NoError(t, rdb.Do(ctx, "JSON.SET", "a", "$", `{"x": 1, "nested": {"x": 2, "y": 3}}`).Err())
require.EqualValues(t, 1, rdb.Do(ctx, command, "a", "$.x").Val())
require.Equal(t, `[{"nested":{"x":2,"y":3}}]`, rdb.Do(ctx, "JSON.GET", "a", "$").Val())
}
})

t.Run("JSON.GET with options", func(t *testing.T) {
require.NoError(t, rdb.Do(ctx, "JSON.SET", "a", "$", ` {"x":1, "y":2} `).Err())
require.Equal(t, rdb.Do(ctx, "JSON.GET", "a", "INDENT", " ").Val(), `{ "x":1, "y":2}`)
Expand Down

0 comments on commit d2312a4

Please sign in to comment.