Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
leo authored and leo committed Oct 20, 2021
1 parent f998c1d commit 1968737
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions cache_util/goredis/cluster/ttl.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ func CheckTtlRefresh(Redis *redis.ClusterClient, ctx context.Context, keystr str
func SmartCheck_LocalCache_Redis(ctx context.Context, Redis *redis.ClusterClient, LocalCache *gofastcache.LocalCache, keystr string) (interface{}, int64, bool) {
localvalue, ttl, localexist := LocalCache.Get(keystr)
if !cache_util.CheckTtlRefresh(ttl) && localexist {
rresult, err := Redis.Get(ctx, keystr).Result()
if err == nil && rresult == LocalCache.GetRand(keystr) {
randSyncStr := keystr + ":randsync"
rresult, err := Redis.Get(ctx, randSyncStr).Result()
if err == nil && rresult == LocalCache.GetRand(randSyncStr) {
return localvalue, ttl, true
}
}
Expand All @@ -45,6 +46,7 @@ func SmartCheck_LocalCache_Redis(ctx context.Context, Redis *redis.ClusterClient

func SmartSet_LocalCache_Redis(ctx context.Context, Redis *redis.ClusterClient, LocalCache *gofastcache.LocalCache, keystr string, value interface{}, ttlSecond int64) {
LocalCache.Set(keystr, value, ttlSecond)
strsrc := LocalCache.SetRand(keystr, ttlSecond+10)
Redis.Set(ctx, keystr, strsrc, time.Duration(ttlSecond+30)*time.Second)
randSyncStr := keystr + ":randsync"
strsrc := LocalCache.SetRand(randSyncStr, ttlSecond+10)
Redis.Set(ctx, randSyncStr, strsrc, time.Duration(ttlSecond+30)*time.Second)
}

0 comments on commit 1968737

Please sign in to comment.