diff --git a/src/commands/commander.cc b/src/commands/commander.cc index 6ac10581606..54fe1aeacf5 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 &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 51be1347fd7..18fb2d3df1e 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()