Skip to content

Commit

Permalink
bugfix: execCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
HDT3213 committed May 20, 2023
1 parent edfbe75 commit c7dda00
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
28 changes: 13 additions & 15 deletions database/commandinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,21 @@ const (
)

func execCommand(args [][]byte) redis.Reply {
n := len(args)
if n > 1 {
subCommand := strings.ToLower(string(args[1]))
if subCommand == "info" {
return getCommands(args[2:])
} else if subCommand == "count" {
return protocol.MakeIntReply(int64(len(cmdTable)))
} else if subCommand == "getkeys" {
if n < 2 {
return protocol.MakeErrReply("Unknown subcommand or wrong number of arguments for '" + subCommand + "'")
}
return getKeys(args[2:])
} else {
return protocol.MakeErrReply("Unknown subcommand or wrong number of arguments for '" + subCommand + "'")
if len(args) == 0 {
return getAllGodisCommandReply()
}
subCommand := strings.ToLower(string(args[0]))
if subCommand == "info" {
return getCommands(args[1:])
} else if subCommand == "count" {
return protocol.MakeIntReply(int64(len(cmdTable)))
} else if subCommand == "getkeys" {
if len(args) < 2 {
return protocol.MakeErrReply("wrong number of arguments for 'command|" + subCommand + "'")
}
return getKeys(args[1:])
} else {
return getAllGodisCommandReply()
return protocol.MakeErrReply("Unknown subcommand '" + subCommand + "'")
}
}

Expand Down
2 changes: 1 addition & 1 deletion database/commandinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ func TestCommandInfo(t *testing.T) {
ret = testServer.Exec(c, utils.ToCmdLine("command", "getkeys", "mset", "a", "a", "b", "b"))
asserts.AssertMultiBulkReply(t, ret, []string{"a", "b"})
ret = testServer.Exec(c, utils.ToCmdLine("command", "foobar"))
asserts.AssertErrReply(t, ret, "Unknown subcommand or wrong number of arguments for 'foobar'")
asserts.AssertErrReply(t, ret, "Unknown subcommand 'foobar'")
}
2 changes: 1 addition & 1 deletion database/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (server *Server) Exec(c redis.Connection, cmdLine [][]byte) (result redis.R
}
return server.execSlaveOf(c, cmdLine[1:])
} else if cmdName == "command" {
return execCommand(cmdLine)
return execCommand(cmdLine[1:])
}

// read only slave
Expand Down

0 comments on commit c7dda00

Please sign in to comment.