Export scripter interface

This commit is contained in:
Vladimir Mihailenco 2021-01-26 11:57:16 +02:00
parent 99852af14d
commit bf010a705d
2 changed files with 10 additions and 10 deletions

View File

@ -262,7 +262,7 @@ var _ = Describe("races", func() {
Expect(n).To(Equal(int64(N))) Expect(n).To(Equal(int64(N)))
}) })
It("should BLPop", func() { PIt("should BLPop", func() {
var received uint32 var received uint32
wg := performAsync(C, func(id int) { wg := performAsync(C, func(id int) {

View File

@ -8,7 +8,7 @@ import (
"strings" "strings"
) )
type scripter interface { type Scripter interface {
Eval(ctx context.Context, script string, keys []string, args ...interface{}) *Cmd Eval(ctx context.Context, script string, keys []string, args ...interface{}) *Cmd
EvalSha(ctx context.Context, sha1 string, keys []string, args ...interface{}) *Cmd EvalSha(ctx context.Context, sha1 string, keys []string, args ...interface{}) *Cmd
ScriptExists(ctx context.Context, hashes ...string) *BoolSliceCmd ScriptExists(ctx context.Context, hashes ...string) *BoolSliceCmd
@ -16,9 +16,9 @@ type scripter interface {
} }
var ( var (
_ scripter = (*Client)(nil) _ Scripter = (*Client)(nil)
_ scripter = (*Ring)(nil) _ Scripter = (*Ring)(nil)
_ scripter = (*ClusterClient)(nil) _ Scripter = (*ClusterClient)(nil)
) )
type Script struct { type Script struct {
@ -38,25 +38,25 @@ func (s *Script) Hash() string {
return s.hash return s.hash
} }
func (s *Script) Load(ctx context.Context, c scripter) *StringCmd { func (s *Script) Load(ctx context.Context, c Scripter) *StringCmd {
return c.ScriptLoad(ctx, s.src) return c.ScriptLoad(ctx, s.src)
} }
func (s *Script) Exists(ctx context.Context, c scripter) *BoolSliceCmd { func (s *Script) Exists(ctx context.Context, c Scripter) *BoolSliceCmd {
return c.ScriptExists(ctx, s.hash) return c.ScriptExists(ctx, s.hash)
} }
func (s *Script) Eval(ctx context.Context, c scripter, keys []string, args ...interface{}) *Cmd { func (s *Script) Eval(ctx context.Context, c Scripter, keys []string, args ...interface{}) *Cmd {
return c.Eval(ctx, s.src, keys, args...) return c.Eval(ctx, s.src, keys, args...)
} }
func (s *Script) EvalSha(ctx context.Context, c scripter, keys []string, args ...interface{}) *Cmd { func (s *Script) EvalSha(ctx context.Context, c Scripter, keys []string, args ...interface{}) *Cmd {
return c.EvalSha(ctx, s.hash, keys, args...) return c.EvalSha(ctx, s.hash, keys, args...)
} }
// Run optimistically uses EVALSHA to run the script. If script does not exist // Run optimistically uses EVALSHA to run the script. If script does not exist
// it is retried using EVAL. // it is retried using EVAL.
func (s *Script) Run(ctx context.Context, c scripter, keys []string, args ...interface{}) *Cmd { func (s *Script) Run(ctx context.Context, c Scripter, keys []string, args ...interface{}) *Cmd {
r := s.EvalSha(ctx, c, keys, args...) r := s.EvalSha(ctx, c, keys, args...)
if err := r.Err(); err != nil && strings.HasPrefix(err.Error(), "NOSCRIPT ") { if err := r.Err(); err != nil && strings.HasPrefix(err.Error(), "NOSCRIPT ") {
return s.Eval(ctx, c, keys, args...) return s.Eval(ctx, c, keys, args...)