From c342345c0bd102222b870d9b9c5cf57fd2b74fa3 Mon Sep 17 00:00:00 2001 From: qhd <1766646056@qq.com> Date: Fri, 26 Dec 2025 17:45:11 +0800 Subject: [PATCH] =?UTF-8?q?redis=20Lock=E6=96=B9=E6=B3=95=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0-=E9=94=81=E9=87=8D=E8=AF=95=E6=AC=A1=E6=95=B0?= =?UTF-8?q?=E8=80=97=E5=B0=BD=E8=BF=94=E5=9B=9E=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- redis/redis.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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) {