From f69c7bd996eff113dc8da00097de688b60438e15 Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Fri, 14 Oct 2016 10:10:58 +0300 Subject: [PATCH] Lowercase command name. Updates #399. --- command.go | 5 +++++ internal/util.go | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 internal/util.go diff --git a/command.go b/command.go index 8ac048a..ce0dc78 100644 --- a/command.go +++ b/command.go @@ -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} } diff --git a/internal/util.go b/internal/util.go new file mode 100644 index 0000000..5986cc5 --- /dev/null +++ b/internal/util.go @@ -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 +}