fix(redis): lock acquisition fails open per spec §9
This commit is contained in:
@@ -67,8 +67,12 @@ func (r *R) Lock(ctx context.Context, key string, ttl time.Duration) (func(), bo
|
||||
rand.Read(b)
|
||||
tok := hex.EncodeToString(b)
|
||||
ok, err := r.c.SetNX(ctx, key, tok, ttl).Result()
|
||||
if err != nil || !ok {
|
||||
return noop, false
|
||||
if err != nil { // spec §9: Redis 故障降级放行,锁只做尽力去重
|
||||
log.Printf("redis lock %s: %v (proceeding without lock)", key, err)
|
||||
return noop, true
|
||||
}
|
||||
if !ok {
|
||||
return noop, false // 锁被持有,别的副本在扫
|
||||
}
|
||||
return func() {
|
||||
r.c.Eval(ctx,
|
||||
|
||||
Reference in New Issue
Block a user