mirror of https://github.com/go-redis/redis.git
Merge pull request #406 from go-redis/fix/cmd-name-lowercase
Lowercase command name.
This commit is contained in:
commit
24aa071f7c
|
@ -146,6 +146,10 @@ func (cmd *baseCmd) setErr(e error) {
|
|||
}
|
||||
|
||||
func newBaseCmd(args []interface{}) baseCmd {
|
||||
if len(args) > 0 {
|
||||
// Cmd name is expected to be in lower case.
|
||||
args[0] = internal.ToLower(args[0].(string))
|
||||
}
|
||||
return baseCmd{_args: args}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package internal
|
||||
|
||||
func ToLower(s string) string {
|
||||
if isLower(s) {
|
||||
return s
|
||||
}
|
||||
|
||||
b := make([]byte, len(s))
|
||||
for i := range b {
|
||||
c := s[i]
|
||||
if c >= 'A' && c <= 'Z' {
|
||||
c += 'a' - 'A'
|
||||
}
|
||||
b[i] = c
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func isLower(s string) bool {
|
||||
for i := 0; i < len(s); i++ {
|
||||
c := s[i]
|
||||
if c >= 'A' && c <= 'Z' {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
Loading…
Reference in New Issue