Skip to content

Commit

Permalink
Accept interface{} in Eval. Fixes redis#243.
Browse files Browse the repository at this point in the history
  • Loading branch information
vmihailenco committed Apr 9, 2016
1 parent b351402 commit 5e5a540
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,15 +288,15 @@ 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()
if err != nil {
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: <nil> redis: nil
Expand Down
18 changes: 9 additions & 9 deletions script.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}

0 comments on commit 5e5a540

Please sign in to comment.