Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make COMMAND command consistent with redis when the renamed command exists #2123

Merged
merged 1 commit into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/commands/commander.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down
40 changes: 39 additions & 1 deletion tests/gocase/unit/command/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
Loading