From df5fe0c756ff7d8888052fb81f8d2fdc54b838fb Mon Sep 17 00:00:00 2001 From: steden <1470804@qq.com> Date: Fri, 9 Sep 2022 00:36:13 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E8=80=97=E6=97=B6=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cacheInRedis.go | 30 +++--------------------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/cacheInRedis.go b/cacheInRedis.go index 932eddb..81eb475 100644 --- a/cacheInRedis.go +++ b/cacheInRedis.go @@ -5,7 +5,6 @@ import ( "github.com/farseer-go/cache" "github.com/farseer-go/collections" "github.com/farseer-go/fs/flog" - "github.com/farseer-go/fs/stopwatch" "reflect" ) @@ -14,9 +13,6 @@ type cacheInRedis struct { } func (r cacheInRedis) Get(cacheKey cache.CacheKey) collections.ListAny { - sw := stopwatch.StartNew() - defer func() { flog.Debugf("cacheInRedis.Get:%s", sw.GetMillisecondsText()) }() - // 从redis hash中读取到slice redisClient := NewClient(cacheKey.RedisConfigName) lst, err := redisClient.Hash.ToListAny(cacheKey.Key, cacheKey.ItemType) @@ -27,9 +23,6 @@ func (r cacheInRedis) Get(cacheKey cache.CacheKey) collections.ListAny { } func (r cacheInRedis) GetItem(cacheKey cache.CacheKey, cacheId string) any { - sw := stopwatch.StartNew() - defer func() { flog.Debugf("cacheInRedis.GetItem:%s", sw.GetMillisecondsText()) }() - // 动态创建实体 entityPtr := reflect.New(cacheKey.ItemType).Interface() @@ -46,8 +39,9 @@ func (r cacheInRedis) GetItem(cacheKey cache.CacheKey, cacheId string) any { } func (r cacheInRedis) Set(cacheKey cache.CacheKey, val collections.ListAny) { - sw := stopwatch.StartNew() - defer func() { flog.Debugf("cacheInRedis.Set:%s", sw.GetMillisecondsText()) }() + if val.Count() == 0 { + return + } // 将ListAny转成map values := make(map[string]any) @@ -68,9 +62,6 @@ func (r cacheInRedis) Set(cacheKey cache.CacheKey, val collections.ListAny) { } func (r cacheInRedis) SaveItem(cacheKey cache.CacheKey, newVal any) { - sw := stopwatch.StartNew() - defer func() { flog.Debugf("cacheInRedis.SaveItem:%s", sw.GetMillisecondsText()) }() - redisClient := NewClient(cacheKey.RedisConfigName) newValDataKey := cacheKey.GetUniqueId(newVal) err := redisClient.Hash.SetEntity(cacheKey.Key, newValDataKey, newVal) @@ -80,9 +71,6 @@ func (r cacheInRedis) SaveItem(cacheKey cache.CacheKey, newVal any) { } func (r cacheInRedis) Remove(cacheKey cache.CacheKey, cacheId string) { - sw := stopwatch.StartNew() - defer func() { flog.Debugf("cacheInRedis.Remove:%s", sw.GetMillisecondsText()) }() - redisClient := NewClient(cacheKey.RedisConfigName) _, err := redisClient.Hash.Del(cacheKey.Key, cacheId) if err != nil { @@ -91,9 +79,6 @@ func (r cacheInRedis) Remove(cacheKey cache.CacheKey, cacheId string) { } func (r cacheInRedis) Clear(cacheKey cache.CacheKey) { - sw := stopwatch.StartNew() - defer func() { flog.Debugf("cacheInRedis.Clear:%s", sw.GetMillisecondsText()) }() - redisClient := NewClient(cacheKey.RedisConfigName) _, err := redisClient.Key.Del(cacheKey.Key) if err != nil { @@ -102,17 +87,11 @@ func (r cacheInRedis) Clear(cacheKey cache.CacheKey) { } func (r cacheInRedis) Count(cacheKey cache.CacheKey) int { - sw := stopwatch.StartNew() - defer func() { flog.Debugf("cacheInRedis.Count:%s", sw.GetMillisecondsText()) }() - redisClient := NewClient(cacheKey.RedisConfigName) return redisClient.Hash.Count(cacheKey.Key) } func (r cacheInRedis) ExistsItem(cacheKey cache.CacheKey, cacheId string) bool { - sw := stopwatch.StartNew() - defer func() { flog.Debugf("cacheInRedis.ExistsItem:%s", sw.GetMillisecondsText()) }() - redisClient := NewClient(cacheKey.RedisConfigName) exists, err := redisClient.Hash.Exists(cacheKey.Key, cacheId) if err != nil { @@ -122,9 +101,6 @@ func (r cacheInRedis) ExistsItem(cacheKey cache.CacheKey, cacheId string) bool { } func (r cacheInRedis) ExistsKey(cacheKey cache.CacheKey) bool { - sw := stopwatch.StartNew() - defer func() { flog.Debugf("cacheInRedis.ExistsKey:%s", sw.GetMillisecondsText()) }() - redisClient := NewClient(cacheKey.RedisConfigName) exists, err := redisClient.Key.Exists(cacheKey.Key) if err != nil {