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 d2312a4c Add the support of JSON.FORGET command (#1917)
d2312a4c is described below
commit d2312a4c19ea43f91f670e29f4db7952510a7ebe
Author: hulk <[email protected]>
AuthorDate: Sun Dec 3 22:37:57 2023 +0800
Add the support of JSON.FORGET command (#1917)
---
src/commands/cmd_json.cc | 2 ++
tests/gocase/unit/type/json/json_test.go | 13 +++++++++++++
2 files changed, 15 insertions(+)
diff --git a/src/commands/cmd_json.cc b/src/commands/cmd_json.cc
index 9f0e8ffc..396c0e85 100644
--- a/src/commands/cmd_json.cc
+++ b/src/commands/cmd_json.cc
@@ -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), );
diff --git a/tests/gocase/unit/type/json/json_test.go
b/tests/gocase/unit/type/json/json_test.go
index 7b257309..adf58001 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}`)