diff --git a/redis/redis.go b/redis/redis.go index 3e8a5b0..df2dacb 100644 --- a/redis/redis.go +++ b/redis/redis.go @@ -2,6 +2,7 @@ package redis import ( "context" + "errors" "strings" "sync" "time" @@ -37,7 +38,7 @@ func Lock(ctx context.Context, key string, expireSeconds int64, fn func(ctx cont limit := 3 LOOP: if limit < 0 { - return + return false, errors.New("锁重试次数耗尽") } limit-- if val, err := RedisClient.Set(ctx, key, true, gredis.SetOption{ @@ -46,7 +47,7 @@ LOOP: }, NX: true, }); err != nil { - return + return false, err } else { if val.Bool() { defer func(RedisClient *gredis.Redis, ctx context.Context, key string) {