From 6efdac7babaaf366a47ca0d060f07f392cceeae7 Mon Sep 17 00:00:00 2001 From: ayflying Date: Thu, 28 Aug 2025 18:16:47 +0800 Subject: [PATCH] =?UTF-8?q?redis=E5=88=B7=E6=96=B0=E5=88=97=E8=A1=A8?= =?UTF-8?q?=EF=BC=8C=E5=85=81=E8=AE=B8=E6=89=93=E6=96=AD=EF=BC=8C=E9=98=B2?= =?UTF-8?q?=E6=AD=A2=E8=BF=87=E9=95=BF=E7=9A=84=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/logic/gameAct/gameAct.go | 10 ++++++++-- internal/logic/gameKv/gameKv.go | 4 +++- tools/redis.go | 3 +++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/internal/logic/gameAct/gameAct.go b/internal/logic/gameAct/gameAct.go index 5eec6d5..bb54907 100644 --- a/internal/logic/gameAct/gameAct.go +++ b/internal/logic/gameAct/gameAct.go @@ -2,6 +2,7 @@ package gameAct import ( "context" + "errors" "fmt" "strconv" "strings" @@ -146,7 +147,8 @@ func (s *sGameAct) Save(ctx context.Context, actId int) (err error) { err = tools.Redis.RedisScanV2(cacheKey, func(keys []string) (err error) { //判断是否超时 if gtime.Now().After(RunTimeMax) { - g.Log().Debug(ctx, "执行超时了,停止执行!") + g.Log().Debug(ctx, "act执行超时了,停止执行!") + err = errors.New("act执行超时了,停止执行!") return } var add = make([]*entity.GameAct, 0) @@ -209,6 +211,7 @@ func (s *sGameAct) Save(ctx context.Context, actId int) (err error) { } //批量写入数据库 + updateCount := 0 if len(delKey) > 0 { for _, v := range update { v.UpdatedAt = gtime.Now() @@ -224,7 +227,10 @@ func (s *sGameAct) Save(ctx context.Context, actId int) (err error) { g.Log().Error(ctx, "本次更新为0,更新数据失败: %v", v) return } + updateCount++ } + g.Log().Debugf(ctx, "当前 %v 更新数据库: %v 条", actId, updateCount) + update = make([]*entity.GameAct, 0) var count int64 @@ -237,6 +243,7 @@ func (s *sGameAct) Save(ctx context.Context, actId int) (err error) { return } count, _ = dbRes.RowsAffected() + g.Log().Debugf(ctx, "当前 %v 写入数据库: %v 条", actId, count) } for _, v := range delKey { @@ -247,7 +254,6 @@ func (s *sGameAct) Save(ctx context.Context, actId int) (err error) { } delKey = make([]string, 0) - g.Log().Debugf(ctx, "当前 %v 写入数据库: %v 条", actId, count) } if err != nil { diff --git a/internal/logic/gameKv/gameKv.go b/internal/logic/gameKv/gameKv.go index c4d5aa1..d530d73 100644 --- a/internal/logic/gameKv/gameKv.go +++ b/internal/logic/gameKv/gameKv.go @@ -1,6 +1,7 @@ package gameKv import ( + "errors" "fmt" "strconv" "strings" @@ -56,7 +57,8 @@ func (s *sGameKv) SavesV1() (err error) { err = tools.Redis.RedisScanV2("user:kv:*", func(keys []string) (err error) { //判断是否超时 if gtime.Now().After(RunTimeMax) { - g.Log().Error(ctx, "执行超时了,停止执行!") + g.Log().Error(ctx, "kv执行超时了,停止执行!") + err = errors.New("kv执行超时了,停止执行!") return } diff --git a/tools/redis.go b/tools/redis.go index 2d773c5..d048fca 100644 --- a/tools/redis.go +++ b/tools/redis.go @@ -70,6 +70,9 @@ func (r *redis) RedisScanV2(cacheKey string, _func func([]string) error, _key .. if len(newKeys) > 0 { err = _func(newKeys) + if err != nil { + return err + } } //这个要放在最后