MCPcopy
hub / github.com/redis/go-redis / Exists

Method Exists

script.go:71–91  ·  view source on GitHub ↗
(ctx context.Context, c Scripter)

Source from the content-addressed store, hash-verified

69}
70
71func (s *Script) Exists(ctx context.Context, c Scripter) *BoolSliceCmd {
72 s.mu.RLock()
73 hash := s.hash
74 serverSHA := s.serverSHA
75 s.mu.RUnlock()
76 if hash == "" && serverSHA {
77 // For server-side scripts, obtain digest from Redis first.
78 // If hash is empty, it means SCRIPT LOAD was not called yet, so we check existence of empty hash which will return false.
79 // This avoids unnecessary SCRIPT LOAD just to check existence.
80 if err := s.ensureHash(ctx, c); err != nil {
81 return c.ScriptExists(ctx, "")
82 }
83 s.mu.RLock()
84 hash = s.hash
85 s.mu.RUnlock()
86 }
87 if hash == "" {
88 return c.ScriptExists(ctx, "")
89 }
90 return c.ScriptExists(ctx, hash)
91}
92
93func (s *Script) Eval(ctx context.Context, c Scripter, keys []string, args ...interface{}) *Cmd {
94 return c.Eval(ctx, s.src, keys, args...)

Callers

nothing calls this directly

Calls 2

ensureHashMethod · 0.95
ScriptExistsMethod · 0.65

Tested by

no test coverage detected