From b8ef5cd34ce648204e66088dd644d72c4072a0ea Mon Sep 17 00:00:00 2001 From: Mary Smiley <71322561+bothyouandme@users.noreply.github.com> Date: Sat, 16 Mar 2024 09:36:49 +0800 Subject: [PATCH] Update cache.go --- model/cache.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/model/cache.go b/model/cache.go index 8294e73..7b9f053 100644 --- a/model/cache.go +++ b/model/cache.go @@ -18,6 +18,8 @@ var ( UserId2GroupCacheSeconds = common.SyncFrequency UserId2QuotaCacheSeconds = common.SyncFrequency UserId2StatusCacheSeconds = common.SyncFrequency + UserId2timeCacheSeconds = common.SyncFrequency + ) // 仅用于定时同步缓存 @@ -160,6 +162,26 @@ func CacheGetUserQuota(id int) (quota int, err error) { return quota, err } +func CacheGetUserRefreshTimeStamp(id int) (RefreshTimeStamp int64, err error) { + if !common.RedisEnabled { + return GetUserRefreshTimeStamp(id) + } + stampString, err := common.RedisGet(fmt.Sprintf("user_stamp:%d", id)) + if err != nil { + timestamp, err := GetUserRefreshTimeStamp(id) + if err != nil { + return 0, err + } + err = common.RedisSet(fmt.Sprintf("user_stamp:%d", id), fmt.Sprintf("%d", timestamp), time.Duration(UserId2timeCacheSeconds)*time.Second) + if err != nil { + common.SysError("Redis set user timestamp error: " + err.Error()) + } + return timestamp, err + } + timestamp, err := strconv.ParseInt(stampString, 10, 64) + return timestamp, err +} + func CacheUpdateUserQuota(id int) error { if !common.RedisEnabled { return nil @@ -171,6 +193,13 @@ func CacheUpdateUserQuota(id int) error { err = common.RedisSet(fmt.Sprintf("user_quota:%d", id), fmt.Sprintf("%d", quota), time.Duration(UserId2QuotaCacheSeconds)*time.Second) return err } +func CacheUpdateUserRefreshTimeStamp(id int, timestamp int64) error { + if !common.RedisEnabled { + return nil + } + err := common.RedisSet(fmt.Sprintf("user_stamp:%d", id), fmt.Sprintf("%d", timestamp), time.Duration(UserId2QuotaCacheSeconds)*time.Second) + return err +} func CacheDecreaseUserQuota(id int, quota int) error { if !common.RedisEnabled {