From 5e5a540eb124a8994ad7302b741e89f1a1f2ef4b Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Sat, 9 Apr 2016 11:01:33 +0300 Subject: [PATCH] Accept interface{} in Eval. Fixes #243. --- commands.go | 4 ++-- example_test.go | 4 ++-- script.go | 18 +++++++++--------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/commands.go b/commands.go index c5235346..dc6dd08f 100644 --- a/commands.go +++ b/commands.go @@ -1543,7 +1543,7 @@ func (c *commandable) Time() *StringSliceCmd { //------------------------------------------------------------------------------ -func (c *commandable) Eval(script string, keys []string, args []string) *Cmd { +func (c *commandable) Eval(script string, keys []string, args ...interface{}) *Cmd { cmdArgs := make([]interface{}, 3+len(keys)+len(args)) cmdArgs[0] = "EVAL" cmdArgs[1] = script @@ -1563,7 +1563,7 @@ func (c *commandable) Eval(script string, keys []string, args []string) *Cmd { return cmd } -func (c *commandable) EvalSha(sha1 string, keys []string, args []string) *Cmd { +func (c *commandable) EvalSha(sha1 string, keys []string, args ...interface{}) *Cmd { cmdArgs := make([]interface{}, 3+len(keys)+len(args)) cmdArgs[0] = "EVALSHA" cmdArgs[1] = sha1 diff --git a/example_test.go b/example_test.go index 33800228..587ef78a 100644 --- a/example_test.go +++ b/example_test.go @@ -288,7 +288,7 @@ func ExampleScript() { return false `) - n, err := IncrByXX.Run(client, []string{"xx_counter"}, []string{"2"}).Result() + n, err := IncrByXX.Run(client, []string{"xx_counter"}, 2).Result() fmt.Println(n, err) err = client.Set("xx_counter", "40", 0).Err() @@ -296,7 +296,7 @@ func ExampleScript() { panic(err) } - n, err = IncrByXX.Run(client, []string{"xx_counter"}, []string{"2"}).Result() + n, err = IncrByXX.Run(client, []string{"xx_counter"}, 2).Result() fmt.Println(n, err) // Output: redis: nil diff --git a/script.go b/script.go index 3f22f469..c5fc1d2b 100644 --- a/script.go +++ b/script.go @@ -8,8 +8,8 @@ import ( ) type scripter interface { - Eval(script string, keys []string, args []string) *Cmd - EvalSha(sha1 string, keys []string, args []string) *Cmd + Eval(script string, keys []string, args ...interface{}) *Cmd + EvalSha(sha1 string, keys []string, args ...interface{}) *Cmd ScriptExists(scripts ...string) *BoolSliceCmd ScriptLoad(script string) *StringCmd } @@ -35,18 +35,18 @@ func (s *Script) Exists(c scripter) *BoolSliceCmd { return c.ScriptExists(s.src) } -func (s *Script) Eval(c scripter, keys []string, args []string) *Cmd { - return c.Eval(s.src, keys, args) +func (s *Script) Eval(c scripter, keys []string, args ...interface{}) *Cmd { + return c.Eval(s.src, keys, args...) } -func (s *Script) EvalSha(c scripter, keys []string, args []string) *Cmd { - return c.EvalSha(s.hash, keys, args) +func (s *Script) EvalSha(c scripter, keys []string, args ...interface{}) *Cmd { + return c.EvalSha(s.hash, keys, args...) } -func (s *Script) Run(c scripter, keys []string, args []string) *Cmd { - r := s.EvalSha(c, keys, args) +func (s *Script) Run(c scripter, keys []string, args ...interface{}) *Cmd { + r := s.EvalSha(c, keys, args...) if err := r.Err(); err != nil && strings.HasPrefix(err.Error(), "NOSCRIPT ") { - return s.Eval(c, keys, args) + return s.Eval(c, keys, args...) } return r }