From d5d8f62a700824af1f6be2ea2c9e629d0a9d6ce7 Mon Sep 17 00:00:00 2001 From: 80597928 <673421862@qq.com> Date: Fri, 21 Jun 2024 16:07:21 +0800 Subject: [PATCH] fix key no exists --- src/commands/cmd_json.cc | 3 +-- tests/gocase/unit/type/json/json_test.go | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/commands/cmd_json.cc b/src/commands/cmd_json.cc index 8f788953814..7708d2f8785 100644 --- a/src/commands/cmd_json.cc +++ b/src/commands/cmd_json.cc @@ -423,8 +423,7 @@ class CommandJsonArrTrim : public Commander { auto s = json.ArrTrim(args_[1], path_, start_, stop_, &results); if (s.IsNotFound()) { - *output = conn->NilString(); - return Status::OK(); + return {Status::RedisExecErr, "could not perform this operation on a key that doesn't exist"}; } if (!s.ok()) return {Status::RedisExecErr, s.ToString()}; diff --git a/tests/gocase/unit/type/json/json_test.go b/tests/gocase/unit/type/json/json_test.go index 8182db02df5..e720c89be4d 100644 --- a/tests/gocase/unit/type/json/json_test.go +++ b/tests/gocase/unit/type/json/json_test.go @@ -356,7 +356,7 @@ func TestJson(t *testing.T) { t.Run("JSON.ARRTRIM basics", func(t *testing.T) { require.NoError(t, rdb.Del(ctx, "a").Err()) // key no exists - require.EqualError(t, rdb.Do(ctx, "JSON.ARRTRIM", "not_exists", "$", 0, 0).Err(), redis.Nil.Error()) + require.ErrorContains(t, rdb.Do(ctx, "JSON.ARRTRIM", "not_exists", "$", 0, 0).Err(), "could not perform this operation on a key that doesn't exist") // key not json require.NoError(t, rdb.Do(ctx, "SET", "no_json", "1").Err()) require.Error(t, rdb.Do(ctx, "JSON.ARRTRIM", "no_json", "$", 0, 0).Err())