From 636e0ec4f2b0a6622b3552da460c680b46adbcec Mon Sep 17 00:00:00 2001 From: qhd <1766646056@qq.com> Date: Tue, 30 Dec 2025 18:21:50 +0800 Subject: [PATCH] =?UTF-8?q?mongo=E4=B8=AD=E6=B8=85=E9=99=A4=E7=BC=93?= =?UTF-8?q?=E5=AD=98CleanRedis=E6=96=B9=E6=B3=95=E6=94=B9=E6=88=90?= =?UTF-8?q?=E5=85=AC=E5=85=B1=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mongo/mongo.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mongo/mongo.go b/mongo/mongo.go index 466021a..777b2e1 100644 --- a/mongo/mongo.go +++ b/mongo/mongo.go @@ -359,7 +359,7 @@ func (m *MongoDB) FindOne(ctx context.Context, filter bson.M, result interface{} } return } -func cleanRedis(ctx context.Context, filter bson.M, tenantId interface{}, collection string) (err error) { +func (m *MongoDB) CleanRedis(ctx context.Context, filter bson.M, tenantId interface{}, collection string) (err error) { listKeys := fmt.Sprintf(consts.CleanList, tenantId, collection) keys, err := redis.RedisClient.Keys(ctx, listKeys) if err != nil { @@ -413,7 +413,7 @@ func (m *MongoDB) Delete(ctx context.Context, filter bson.M, collection string, return } count = r.DeletedCount - err = cleanRedis(ctx, filter, user.TenantId, collection) + err = m.CleanRedis(ctx, filter, user.TenantId, collection) serverName := g.Cfg().MustGet(ctx, "server.name").String() logRedisKey := fmt.Sprintf("log:%s", serverName) if _, err = redis.AddToStream(ctx, logRedisKey, &dto.RecordCreateLogReq{ @@ -454,7 +454,7 @@ func (m *MongoDB) Update(ctx context.Context, filter bson.M, update bson.M, coll if err != nil { return } - err = cleanRedis(ctx, filter, user.TenantId, collection) + err = m.CleanRedis(ctx, filter, user.TenantId, collection) serverName := g.Cfg().MustGet(ctx, "server.name").String() logRedisKey := fmt.Sprintf("log:%s", serverName) if _, err = redis.AddToStream(ctx, logRedisKey, &dto.RecordCreateLogReq{ @@ -581,7 +581,7 @@ func (m *MongoDB) SaveOrUpdate(ctx context.Context, filter []bson.M, update []bs } // 清理相关缓存 for _, filterItem := range filter { - err = cleanRedis(ctx, filterItem, user.TenantId, collection) + err = m.CleanRedis(ctx, filterItem, user.TenantId, collection) if err != nil { glog.Warning(ctx, "清理Redis缓存失败:", err) } @@ -618,7 +618,7 @@ func (m *MongoDB) Insert(ctx context.Context, documents []interface{}, collectio return } ids = r.InsertedIDs - err = cleanRedis(ctx, bson.M{}, user.TenantId, collection) + err = m.CleanRedis(ctx, bson.M{}, user.TenantId, collection) //写日志 serverName := g.Cfg().MustGet(ctx, "server.name").String() logRedisKey := fmt.Sprintf("log:%s", serverName)