1、波段触发修改
This commit is contained in:
@ -106,6 +106,9 @@ func (rl *RedisLock) AcquireWait(ctx context.Context) (bool, error) {
|
||||
baseInterval = time.Second
|
||||
}
|
||||
|
||||
if baseInterval <= 0 {
|
||||
baseInterval = time.Millisecond * 100 // 至少 100ms
|
||||
}
|
||||
// 随机退避
|
||||
retryInterval := time.Duration(rand.Int63n(int64(baseInterval))) // 随机退避
|
||||
if retryInterval < time.Millisecond*100 {
|
||||
@ -129,6 +132,13 @@ func (rl *RedisLock) AcquireWait(ctx context.Context) (bool, error) {
|
||||
return false, ErrFailed
|
||||
}
|
||||
|
||||
func safeRandomDuration(max time.Duration) time.Duration {
|
||||
if max <= 0 {
|
||||
return 100 * time.Millisecond // fallback default
|
||||
}
|
||||
return time.Duration(rand.Int63n(int64(max)))
|
||||
}
|
||||
|
||||
// Release 释放锁
|
||||
func (rl *RedisLock) Release() (bool, error) {
|
||||
return rl.releaseCtx(context.Background())
|
||||
|
||||
Reference in New Issue
Block a user