mirror of https://github.com/go-redis/redis.git
Accept interface{} in Eval. Fixes #243.
This commit is contained in:
parent
b351402995
commit
5e5a540eb1
|
@ -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
|
||||
|
|
|
@ -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: <nil> redis: nil
|
||||
|
|
18
script.go
18
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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue