MCPcopy
hub / github.com/bsm/redislock / Refresh

Method Refresh

redislock.go:250–268  ·  view source on GitHub ↗

Refresh extends the lock with a new TTL. May return ErrNotObtained if refresh is unsuccessful.

(ctx context.Context, ttl time.Duration, opt *Options)

Source from the content-addressed store, hash-verified

248// Refresh extends the lock with a new TTL.
249// May return ErrNotObtained if refresh is unsuccessful.
250func (l *Lock) Refresh(ctx context.Context, ttl time.Duration, opt *Options) error {
251 if l == nil {
252 return ErrNotObtained
253 }
254 ttlVal := strconv.FormatInt(int64(ttl/time.Millisecond), 10)
255
256 return withRetry(ctx, ttl, opt.getRetryStrategy(), func(ctx context.Context) (bool, error) {
257 _, err := luaRefresh.Run(ctx, l.client, l.keys, l.value, ttlVal).Result()
258 if err == nil {
259 return true, nil
260 }
261 if errors.Is(err, redis.Nil) {
262 // the lock is no longer held by us; retrying cannot recover it.
263 return true, ErrNotObtained
264 }
265 // transient error; allow the retry strategy to try again.
266 return false, err
267 })
268}
269
270// Release manually releases the lock.
271// May return ErrLockNotHeld.

Calls 2

withRetryFunction · 0.85
getRetryStrategyMethod · 0.80