mirror of
https://github.com/HDT3213/godis.git
synced 2025-10-05 08:46:56 +08:00
bugfix: execCommand
This commit is contained in:
@@ -24,24 +24,22 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func execCommand(args [][]byte) redis.Reply {
|
func execCommand(args [][]byte) redis.Reply {
|
||||||
n := len(args)
|
if len(args) == 0 {
|
||||||
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 + "'")
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return getAllGodisCommandReply()
|
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 protocol.MakeErrReply("Unknown subcommand '" + subCommand + "'")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getKeys(args [][]byte) redis.Reply {
|
func getKeys(args [][]byte) redis.Reply {
|
||||||
|
@@ -16,5 +16,5 @@ func TestCommandInfo(t *testing.T) {
|
|||||||
ret = testServer.Exec(c, utils.ToCmdLine("command", "getkeys", "mset", "a", "a", "b", "b"))
|
ret = testServer.Exec(c, utils.ToCmdLine("command", "getkeys", "mset", "a", "a", "b", "b"))
|
||||||
asserts.AssertMultiBulkReply(t, ret, []string{"a", "b"})
|
asserts.AssertMultiBulkReply(t, ret, []string{"a", "b"})
|
||||||
ret = testServer.Exec(c, utils.ToCmdLine("command", "foobar"))
|
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'")
|
||||||
}
|
}
|
||||||
|
@@ -122,7 +122,7 @@ func (server *Server) Exec(c redis.Connection, cmdLine [][]byte) (result redis.R
|
|||||||
}
|
}
|
||||||
return server.execSlaveOf(c, cmdLine[1:])
|
return server.execSlaveOf(c, cmdLine[1:])
|
||||||
} else if cmdName == "command" {
|
} else if cmdName == "command" {
|
||||||
return execCommand(cmdLine)
|
return execCommand(cmdLine[1:])
|
||||||
}
|
}
|
||||||
|
|
||||||
// read only slave
|
// read only slave
|
||||||
|
Reference in New Issue
Block a user