From f58c05d2fbfe981c75fdbb72f20f365f00c01307 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E6=B6=9B?= Date: Thu, 25 Aug 2022 10:09:16 +0800 Subject: [PATCH] =?UTF-8?q?enhance(cache):=E7=B2=BE=E7=AE=80=E5=AD=98?= =?UTF-8?q?=E5=9C=A8=E6=80=A7=E7=BC=93=E5=AD=98=E7=9A=84=E9=94=AE=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cache/exists.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/cache/exists.go b/cache/exists.go index 4a7449a..560b1e1 100644 --- a/cache/exists.go +++ b/cache/exists.go @@ -13,9 +13,8 @@ func assembleExistsKey(entityName string) string { return CacheKey(TAG_EXISTS, keys...) } -func assembleExistsIdentification(id string, additional ...string) string { +func assembleExistsIdentification(additional ...string) string { var b strings.Builder - b.WriteString(id) for _, s := range additional { fmt.Fprintf(&b, ":%s", s) } @@ -23,17 +22,17 @@ func assembleExistsIdentification(id string, additional ...string) string { } // 缓存模型名称明确的、包含指定ID以及一些附加条件的记录 -func CacheExists(entityName, id string, conditions ...string) error { +func CacheExists(entityName string, conditions ...string) error { existskey := assembleExistsKey(entityName) - identification := assembleExistsIdentification(id, conditions...) + identification := assembleExistsIdentification(conditions...) result := global.RedisConn.SAdd(global.Ctx, existskey, identification) return result.Err() } // 从缓存中获取模型名称明确、包含指定ID以及一些附加条件的实体是否存在的标记,函数在返回false时不保证数据库中相关记录也不存在 -func CheckExists(entityName, id string, condtions ...string) (bool, error) { +func CheckExists(entityName string, condtions ...string) (bool, error) { existsKey := assembleExistsKey(entityName) - identification := assembleExistsIdentification(id, condtions...) + identification := assembleExistsIdentification(condtions...) result := global.RedisConn.SIsMember(global.Ctx, existsKey, identification) return result.Val(), result.Err() }