diff --git a/src/commands/cmd_json.cc b/src/commands/cmd_json.cc index 9f0e8ffcc3b..396c0e8539f 100644 --- a/src/commands/cmd_json.cc +++ b/src/commands/cmd_json.cc @@ -549,6 +549,8 @@ REDIS_REGISTER_COMMANDS(MakeCmdAttr("json.set", 4, "write", 1, 1 MakeCmdAttr("json.arrpop", -2, "write", 1, 1, 1), MakeCmdAttr("json.arrindex", -4, "read-only", 1, 1, 1), MakeCmdAttr("json.del", -2, "write", 1, 1, 1), + // JSON.FORGET is an alias for JSON.DEL, refer: https://redis.io/commands/json.forget/ + MakeCmdAttr("json.forget", -2, "write", 1, 1, 1), MakeCmdAttr("json.numincrby", 4, "write", 1, 1, 1), MakeCmdAttr("json.nummultby", 4, "write", 1, 1, 1), ); diff --git a/tests/gocase/unit/type/json/json_test.go b/tests/gocase/unit/type/json/json_test.go index 7b257309196..adf580019fa 100644 --- a/tests/gocase/unit/type/json/json_test.go +++ b/tests/gocase/unit/type/json/json_test.go @@ -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}`)