mongo中清除缓存CleanRedis方法改成公共的
This commit is contained in:
@@ -359,7 +359,7 @@ func (m *MongoDB) FindOne(ctx context.Context, filter bson.M, result interface{}
|
|||||||
}
|
}
|
||||||
return
|
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)
|
listKeys := fmt.Sprintf(consts.CleanList, tenantId, collection)
|
||||||
keys, err := redis.RedisClient.Keys(ctx, listKeys)
|
keys, err := redis.RedisClient.Keys(ctx, listKeys)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -413,7 +413,7 @@ func (m *MongoDB) Delete(ctx context.Context, filter bson.M, collection string,
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
count = r.DeletedCount
|
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()
|
serverName := g.Cfg().MustGet(ctx, "server.name").String()
|
||||||
logRedisKey := fmt.Sprintf("log:%s", serverName)
|
logRedisKey := fmt.Sprintf("log:%s", serverName)
|
||||||
if _, err = redis.AddToStream(ctx, logRedisKey, &dto.RecordCreateLogReq{
|
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 {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = cleanRedis(ctx, filter, user.TenantId, collection)
|
err = m.CleanRedis(ctx, filter, user.TenantId, collection)
|
||||||
serverName := g.Cfg().MustGet(ctx, "server.name").String()
|
serverName := g.Cfg().MustGet(ctx, "server.name").String()
|
||||||
logRedisKey := fmt.Sprintf("log:%s", serverName)
|
logRedisKey := fmt.Sprintf("log:%s", serverName)
|
||||||
if _, err = redis.AddToStream(ctx, logRedisKey, &dto.RecordCreateLogReq{
|
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 {
|
for _, filterItem := range filter {
|
||||||
err = cleanRedis(ctx, filterItem, user.TenantId, collection)
|
err = m.CleanRedis(ctx, filterItem, user.TenantId, collection)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Warning(ctx, "清理Redis缓存失败:", err)
|
glog.Warning(ctx, "清理Redis缓存失败:", err)
|
||||||
}
|
}
|
||||||
@@ -618,7 +618,7 @@ func (m *MongoDB) Insert(ctx context.Context, documents []interface{}, collectio
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
ids = r.InsertedIDs
|
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()
|
serverName := g.Cfg().MustGet(ctx, "server.name").String()
|
||||||
logRedisKey := fmt.Sprintf("log:%s", serverName)
|
logRedisKey := fmt.Sprintf("log:%s", serverName)
|
||||||
|
|||||||
Reference in New Issue
Block a user