Merge pull request #405 from go-redis/fix/lowercase-name

Lowercase command name. Updates #399.
This commit is contained in:
Vladimir Mihailenco 2016-10-14 10:48:01 +03:00 committed by GitHub
commit 1579a9df5f
2 changed files with 32 additions and 0 deletions

View File

@ -7,6 +7,7 @@ import (
"strings"
"time"
"gopkg.in/redis.v4/internal"
"gopkg.in/redis.v4/internal/pool"
"gopkg.in/redis.v4/internal/proto"
)
@ -130,6 +131,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}
}

27
internal/util.go Normal file
View File

@ -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
}