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

Method ensureHash

script.go:103–126  ·  view source on GitHub ↗

ensureHash ensures that s.hash is populated by using SCRIPT LOAD. It never calls SHA-1 in Go; Redis computes and returns the digest.

(ctx context.Context, c Scripter)

Source from the content-addressed store, hash-verified

101// ensureHash ensures that s.hash is populated by using SCRIPT LOAD.
102// It never calls SHA-1 in Go; Redis computes and returns the digest.
103func (s *Script) ensureHash(ctx context.Context, c Scripter) error {
104 // Fast path: read lock, return if hash is already set.
105 s.mu.RLock()
106 if s.hash != "" {
107 s.mu.RUnlock()
108 return nil
109 }
110 s.mu.RUnlock()
111
112 // Slow path: acquire write lock and load.
113 s.mu.Lock()
114 if s.hash != "" {
115 s.mu.Unlock()
116 return nil
117 }
118 cmd := c.ScriptLoad(ctx, s.src)
119 if err := cmd.Err(); err != nil {
120 s.mu.Unlock()
121 return err
122 }
123 s.hash = cmd.Val()
124 s.mu.Unlock()
125 return nil
126}
127
128func (s *Script) EvalSha(ctx context.Context, c Scripter, keys []string, args ...interface{}) *Cmd {
129 // Default behavior: use client-side SHA-1 computed in NewScript.

Callers 3

ExistsMethod · 0.95
EvalShaMethod · 0.95
EvalShaROMethod · 0.95

Calls 3

ScriptLoadMethod · 0.65
ErrMethod · 0.65
ValMethod · 0.45

Tested by

no test coverage detected