aboutsummaryrefslogtreecommitdiff
path: root/vendor/gopkg.in/redis.v2/script.go
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2017-02-09 19:48:13 -0500
committerUnknwon <u@gogs.io>2017-02-09 19:48:13 -0500
commit2fd69f13d9599a6c58b47225565163fd7d87889f (patch)
treefd19e868e1c2e95a5fb83a268f6e393669d6ee79 /vendor/gopkg.in/redis.v2/script.go
parenteb66060cd7b9bce996b1d75ae80ce1ef31d5ce62 (diff)
vendor: check in vendors
Bye bye glide...
Diffstat (limited to 'vendor/gopkg.in/redis.v2/script.go')
-rw-r--r--vendor/gopkg.in/redis.v2/script.go52
1 files changed, 52 insertions, 0 deletions
diff --git a/vendor/gopkg.in/redis.v2/script.go b/vendor/gopkg.in/redis.v2/script.go
new file mode 100644
index 00000000..96c35f51
--- /dev/null
+++ b/vendor/gopkg.in/redis.v2/script.go
@@ -0,0 +1,52 @@
+package redis
+
+import (
+ "crypto/sha1"
+ "encoding/hex"
+ "io"
+ "strings"
+)
+
+type scripter interface {
+ Eval(script string, keys []string, args []string) *Cmd
+ EvalSha(sha1 string, keys []string, args []string) *Cmd
+ ScriptExists(scripts ...string) *BoolSliceCmd
+ ScriptLoad(script string) *StringCmd
+}
+
+type Script struct {
+ src, hash string
+}
+
+func NewScript(src string) *Script {
+ h := sha1.New()
+ io.WriteString(h, src)
+ return &Script{
+ src: src,
+ hash: hex.EncodeToString(h.Sum(nil)),
+ }
+}
+
+func (s *Script) Load(c scripter) *StringCmd {
+ return c.ScriptLoad(s.src)
+}
+
+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) EvalSha(c scripter, keys []string, args []string) *Cmd {
+ return c.EvalSha(s.hash, keys, args)
+}
+
+func (s *Script) Run(c *Client, keys []string, args []string) *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 r
+}