This is an automated email from the ASF dual-hosted git repository.
hulk 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 350816c2 Make COMMAND command consistent with redis when the renamed
command exists (#2123)
350816c2 is described below
commit 350816c2cc3beba75b938b40db54268b8d80edc9
Author: Myth <[email protected]>
AuthorDate: Wed Feb 28 22:05:41 2024 +0800
Make COMMAND command consistent with redis when the renamed command exists
(#2123)
---
src/commands/commander.cc | 8 +++----
tests/gocase/unit/command/command_test.go | 40 ++++++++++++++++++++++++++++++-
2 files changed, 43 insertions(+), 5 deletions(-)
diff --git a/src/commands/commander.cc b/src/commands/commander.cc
index 6ac10581..54fe1aea 100644
--- a/src/commands/commander.cc
+++ b/src/commands/commander.cc
@@ -55,8 +55,8 @@ std::string CommandTable::GetCommandInfo(const
CommandAttributes *command_attrib
}
void CommandTable::GetAllCommandsInfo(std::string *info) {
- info->append(redis::MultiLen(original_commands.size()));
- for (const auto &iter : original_commands) {
+ info->append(redis::MultiLen(commands.size()));
+ for (const auto &iter : commands) {
auto command_attribute = iter.second;
auto command_info = GetCommandInfo(command_attribute);
info->append(command_info);
@@ -66,8 +66,8 @@ void CommandTable::GetAllCommandsInfo(std::string *info) {
void CommandTable::GetCommandsInfo(std::string *info, const
std::vector<std::string> &cmd_names) {
info->append(redis::MultiLen(cmd_names.size()));
for (const auto &cmd_name : cmd_names) {
- auto cmd_iter = original_commands.find(util::ToLower(cmd_name));
- if (cmd_iter == original_commands.end()) {
+ auto cmd_iter = commands.find(util::ToLower(cmd_name));
+ if (cmd_iter == commands.end()) {
info->append(NilString(RESP::v2));
} else {
auto command_attribute = cmd_iter->second;
diff --git a/tests/gocase/unit/command/command_test.go
b/tests/gocase/unit/command/command_test.go
index 51be1347..18fb2d3d 100644
--- a/tests/gocase/unit/command/command_test.go
+++ b/tests/gocase/unit/command/command_test.go
@@ -28,7 +28,10 @@ import (
)
func TestCommand(t *testing.T) {
- srv := util.StartServer(t, map[string]string{})
+ srv := util.StartServer(t, map[string]string{
+ "rename-command KEYS": "RENAMED_KEYS",
+ "rename-command CONFIG": "''", // remove CONFIG command
+ })
defer srv.Close()
ctx := context.Background()
@@ -50,6 +53,41 @@ func TestCommand(t *testing.T) {
require.EqualValues(t, 1, v[5])
})
+ t.Run("acquire renamed command info by COMMAND INFO", func(t
*testing.T) {
+ r := rdb.Do(ctx, "COMMAND", "INFO", "KEYS")
+ vs, err := r.Slice()
+ require.NoError(t, err)
+ require.Len(t, vs, 1)
+ require.Nil(t, vs[0])
+
+ r = rdb.Do(ctx, "COMMAND", "INFO", "RENAMED_KEYS")
+ vs, err = r.Slice()
+ require.NoError(t, err)
+ require.Len(t, vs, 1)
+ v := vs[0].([]interface{})
+ require.Len(t, v, 6)
+ require.Equal(t, "keys", v[0])
+ require.EqualValues(t, 2, v[1])
+ require.Equal(t, []interface{}{"readonly"}, v[2])
+ require.EqualValues(t, 0, v[3])
+ require.EqualValues(t, 0, v[4])
+ require.EqualValues(t, 0, v[5])
+ })
+
+ t.Run("renamed command can be acquired by COMMAND", func(t *testing.T) {
+ commandInfos := rdb.Command(ctx).Val()
+ require.NotNil(t, commandInfos)
+ _, found := commandInfos["keys"]
+ require.True(t, found)
+ })
+
+ t.Run("removed command can not be acquired by COMMAND", func(t
*testing.T) {
+ commandInfos := rdb.Command(ctx).Val()
+ require.NotNil(t, commandInfos)
+ _, found := commandInfos["config"]
+ require.True(t, found)
+ })
+
t.Run("command entry length check", func(t *testing.T) {
r := rdb.Do(ctx, "COMMAND")
vs, err := r.Slice()