Closed KM612 closed 8 months ago
To do that, you need to pass a context with a custom deadline. At the moment, the TTL is used by default https://github.com/bsm/redislock/blob/main/redislock.go#L89.
Do this:
ctx, cancel = context.WithDeadline(ctx, time.Now().Add(time.Minute)) // wait for up-to 60s
defer cancel()
lock, err := locker.Obtain(ctx, ...)
great, thank you
lock, err := locker.Obtain(ctx, fmt.Sprintf("update-ml-folder:%v", folder.ID), 12*time.Second, &redislock.Options{ RetryStrategy: redislock.LimitRetry(redislock.LinearBackoff(2*time.Second), 30), })
like this code, it will timeout after 12 second(if some one also hold the lock), I hope it will wait 60 second and when it get the lock success,also will hold the lock 12 second