修改-redis删除单条查询记录
This commit is contained in:
@@ -4,4 +4,4 @@ const CleanList = "list:tenantId-%v:collection-%s:*"
|
|||||||
const CleanCount = "count:tenantId-%v:collection-%s:*"
|
const CleanCount = "count:tenantId-%v:collection-%s:*"
|
||||||
const List = "list:tenantId-%v:collection-%s:filter:%s:options:%s"
|
const List = "list:tenantId-%v:collection-%s:filter:%s:options:%s"
|
||||||
const Count = "count:tenantId-%v:collection-%s:filter:%s"
|
const Count = "count:tenantId-%v:collection-%s:filter:%s"
|
||||||
const One = "one:tenantId-%v:collection-%s:filter:%s:*"
|
const One = "one:tenantId-%v:collection-%s:filter:%s"
|
||||||
|
|||||||
@@ -184,8 +184,7 @@ func FindOne(ctx context.Context, filter bson.M, result interface{}, collection
|
|||||||
}
|
}
|
||||||
filter["isDeleted"] = false
|
filter["isDeleted"] = false
|
||||||
filterMap := utils.OrderMap(filter)
|
filterMap := utils.OrderMap(filter)
|
||||||
optsMap := oneOptionsToMap(ctx, opts...)
|
redisKey := fmt.Sprintf(consts.One, user.TenantId, collection, gconv.String(filterMap))
|
||||||
redisKey := fmt.Sprintf(consts.One, user.TenantId, collection, gconv.String(filterMap), gconv.String(optsMap))
|
|
||||||
resultStr, err := redis.RedisClient.Get(ctx, redisKey)
|
resultStr, err := redis.RedisClient.Get(ctx, redisKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@@ -209,7 +208,7 @@ func FindOne(ctx context.Context, filter bson.M, result interface{}, collection
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
func cleanRedis(ctx context.Context, tenantId interface{}, collection string) (err error) {
|
func 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 {
|
||||||
@@ -232,7 +231,11 @@ func cleanRedis(ctx context.Context, tenantId interface{}, collection string) (e
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
oneKey := fmt.Sprintf(consts.One, tenantId, collection)
|
filter["isDeleted"] = false
|
||||||
|
delete(filter, "tenantId")
|
||||||
|
filterMap := utils.OrderMap(filter)
|
||||||
|
oneKey := fmt.Sprintf(consts.One, tenantId, collection, gconv.String(filterMap))
|
||||||
|
fmt.Println(gconv.String(filterMap))
|
||||||
_, err = redis.RedisClient.Del(ctx, oneKey)
|
_, err = redis.RedisClient.Del(ctx, oneKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@@ -256,7 +259,7 @@ func Delete(ctx context.Context, filter bson.M, collection string, opts ...optio
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
count = r.DeletedCount
|
count = r.DeletedCount
|
||||||
err = cleanRedis(ctx, user.TenantId, collection)
|
err = cleanRedis(ctx, filter, user.TenantId, collection)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -280,7 +283,7 @@ func Update(ctx context.Context, filter bson.M, update bson.M, collection string
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = cleanRedis(ctx, user.TenantId, collection)
|
err = cleanRedis(ctx, filter, user.TenantId, collection)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -307,7 +310,7 @@ func Insert(ctx context.Context, documents []interface{}, collection string, opt
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
ids = r.InsertedIDs
|
ids = r.InsertedIDs
|
||||||
err = cleanRedis(ctx, user.TenantId, collection)
|
err = cleanRedis(ctx, bson.M{}, user.TenantId, collection)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user