From 02b3e275d0c73e18e4fd6dc4e5b1386d737db10a Mon Sep 17 00:00:00 2001 From: ayflying Date: Tue, 2 Dec 2025 10:39:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9A=82=E6=97=B6=E5=B1=8F=E8=94=BD=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E7=9A=84=E5=88=A0=E9=99=A4=EF=BC=8C=E6=9D=A5=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E6=8C=81=E4=B9=85=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/logic/gameAct/gameAct.go | 40 ++++++++++++++++--------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/internal/logic/gameAct/gameAct.go b/internal/logic/gameAct/gameAct.go index da3759d..20706a7 100644 --- a/internal/logic/gameAct/gameAct.go +++ b/internal/logic/gameAct/gameAct.go @@ -237,7 +237,7 @@ func (s *sGameAct) Save(ctx context.Context, actId int) (err error) { } //删除缓存 - go s.DelCacheKey(ctx, v.ActId, v.Uid) + //s.DelCacheKey(ctx, v.ActId, v.Uid) updateCount++ update = make([]*entity.GameAct, 0) @@ -265,10 +265,10 @@ func (s *sGameAct) Save(ctx context.Context, actId int) (err error) { return } - for _, v2 := range add { - //删除缓存 - go s.DelCacheKey(ctx, v2.ActId, v2.Uid) - } + //for _, v2 := range add { + // //删除缓存 + // s.DelCacheKey(ctx, v2.ActId, v2.Uid) + //} //g.Log().Debugf(ctx, "当前 %v 写入数据库: %v 条", actId, count) add = make([]*entity.GameAct, 0) @@ -458,7 +458,7 @@ func (s *sGameAct) Cache2Sql(ctx context.Context, add, update []*entity.GameAct) tx, err = g.DB().Begin(ctx) } //删除缓存 - s.DelCacheKey(ctx, v.ActId, v.Uid) + //s.DelCacheKey(ctx, v.ActId, v.Uid) } //循环结束了,最后写入一波 g.Log().Debugf(ctx, "act当前更新数据库: %v 条", updateCount) @@ -489,7 +489,7 @@ func (s *sGameAct) Cache2Sql(ctx context.Context, add, update []*entity.GameAct) tx, err = g.DB().Begin(ctx) } //删除缓存 - s.DelCacheKey(ctx, v.ActId, v.Uid) + //s.DelCacheKey(ctx, v.ActId, v.Uid) } //循环结束了,最后写入一波 @@ -556,7 +556,7 @@ func (s *sGameAct) Cache2SqlChan(ctx context.Context, addChan, updateChan chan * } //删除缓存 - s.DelCacheKey(ctx, v.ActId, v.Uid) + //s.DelCacheKey(ctx, v.ActId, v.Uid) case v, ok := <-updateChan: if !ok { @@ -590,7 +590,7 @@ func (s *sGameAct) Cache2SqlChan(ctx context.Context, addChan, updateChan chan * } //删除缓存 - s.DelCacheKey(ctx, v.ActId, v.Uid) + //s.DelCacheKey(ctx, v.ActId, v.Uid) case <-ctx.Done(): g.Log().Debug(ctx, "act协程被上下文取消") @@ -607,17 +607,19 @@ func (s *sGameAct) Cache2SqlChan(ctx context.Context, addChan, updateChan chan * // 删除缓存key func (s *sGameAct) DelCacheKey(ctx context.Context, aid int, uid int64) { - //如果有活跃,跳过删除 - if getBool, _ := pkg.Cache("redis"). - Contains(ctx, fmt.Sprintf("act:update:%d", uid)); getBool { - return - } + go func() { + //如果有活跃,跳过删除 + if getBool, _ := pkg.Cache("redis"). + Contains(ctx, fmt.Sprintf("act:update:%d", uid)); getBool { + return + } - cacheKey := fmt.Sprintf("act:%v:%v", aid, uid) - _, err := g.Redis().Del(ctx, cacheKey) - if err != nil { - g.Log().Error(ctx, err) - } + cacheKey := fmt.Sprintf("act:%v:%v", aid, uid) + _, err := g.Redis().Del(ctx, cacheKey) + if err != nil { + g.Log().Error(ctx, err) + } + }() } // 清空GetRedDot缓存