更新redis调用
This commit is contained in:
@@ -123,7 +123,7 @@ func (m *MongoDB) Count(ctx context.Context, filter bson.M, collection string) (
|
||||
redisKey := fmt.Sprintf(redis.Count, user.TenantId, collection, filterKey)
|
||||
if !m.noCache {
|
||||
var resultStr *gvar.Var
|
||||
resultStr, err = redis.RedisClient.Get(ctx, redisKey)
|
||||
resultStr, err = redis.RedisClient().Get(ctx, redisKey)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -138,7 +138,7 @@ func (m *MongoDB) Count(ctx context.Context, filter bson.M, collection string) (
|
||||
}
|
||||
count, err = db.Collection(collection).CountDocuments(ctx, filter)
|
||||
if !m.noCache {
|
||||
err = redis.RedisClient.SetEX(ctx, redisKey, count, int64(time.Hour))
|
||||
err = redis.RedisClient().SetEX(ctx, redisKey, count, int64(time.Hour))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -169,7 +169,7 @@ func (m *MongoDB) Find(ctx context.Context, filter bson.M, result interface{}, c
|
||||
redisKey := fmt.Sprintf(redis.List, user.TenantId, collection, filterKey, optionsKey)
|
||||
if !m.noCache {
|
||||
var resultStr *gvar.Var
|
||||
resultStr, err = redis.RedisClient.Get(ctx, redisKey)
|
||||
resultStr, err = redis.RedisClient().Get(ctx, redisKey)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -229,7 +229,7 @@ func (m *MongoDB) Find(ctx context.Context, filter bson.M, result interface{}, c
|
||||
return
|
||||
}
|
||||
if !m.noCache {
|
||||
err = redis.RedisClient.SetEX(ctx, redisKey, result, int64(time.Hour))
|
||||
err = redis.RedisClient().SetEX(ctx, redisKey, result, int64(time.Hour))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -261,7 +261,7 @@ func (m *MongoDB) FindOne(ctx context.Context, filter bson.M, result interface{}
|
||||
redisKey := fmt.Sprintf(redis.One, user.TenantId, collection, filterKey)
|
||||
if !m.noCache {
|
||||
var resultStr *gvar.Var
|
||||
resultStr, err = redis.RedisClient.Get(ctx, redisKey)
|
||||
resultStr, err = redis.RedisClient().Get(ctx, redisKey)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -283,7 +283,7 @@ func (m *MongoDB) FindOne(ctx context.Context, filter bson.M, result interface{}
|
||||
err = nil
|
||||
}
|
||||
if !m.noCache {
|
||||
err = redis.RedisClient.SetEX(ctx, redisKey, result, int64(time.Hour))
|
||||
err = redis.RedisClient().SetEX(ctx, redisKey, result, int64(time.Hour))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -304,23 +304,23 @@ func (m *MongoDB) getDeletedData(ctx context.Context, filter bson.M, collection
|
||||
|
||||
func (m *MongoDB) CleanRedis(ctx context.Context, filter bson.M, tenantId interface{}, collection string) (err error) {
|
||||
listKeys := fmt.Sprintf(redis.CleanList, tenantId, collection)
|
||||
keys, err := redis.RedisClient.Keys(ctx, listKeys)
|
||||
keys, err := redis.RedisClient().Keys(ctx, listKeys)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for _, key := range keys {
|
||||
_, err = redis.RedisClient.Del(ctx, key)
|
||||
_, err = redis.RedisClient().Del(ctx, key)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
countKeys := fmt.Sprintf(redis.CleanCount, tenantId, collection)
|
||||
keys, err = redis.RedisClient.Keys(ctx, countKeys)
|
||||
keys, err = redis.RedisClient().Keys(ctx, countKeys)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for _, key := range keys {
|
||||
_, err = redis.RedisClient.Del(ctx, key)
|
||||
_, err = redis.RedisClient().Del(ctx, key)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -329,7 +329,7 @@ func (m *MongoDB) CleanRedis(ctx context.Context, filter bson.M, tenantId interf
|
||||
delete(filter, "tenantId")
|
||||
filterKey := fmt.Sprintf("%+v", filter)
|
||||
oneKey := fmt.Sprintf(redis.One, tenantId, collection, filterKey)
|
||||
_, err = redis.RedisClient.Del(ctx, oneKey)
|
||||
_, err = redis.RedisClient().Del(ctx, oneKey)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user