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)