From bd1033ac477bb968fa442ee1705fea7a88e7ca96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E6=B6=9B?= Date: Tue, 6 Sep 2022 12:28:06 +0800 Subject: [PATCH] =?UTF-8?q?enhance(cache):=E4=B8=BA=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E5=A2=9E=E5=8A=A060=E7=A7=92=E5=86=85=E7=9A=84=E9=9A=8F?= =?UTF-8?q?=E6=9C=BA=E7=A7=92=E6=95=B0=EF=BC=8C=E4=BB=A5=E9=81=BF=E5=85=8D?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E9=9B=AA=E5=B4=A9=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cache/abstract.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cache/abstract.go b/cache/abstract.go index 9d36c3f..1135c8a 100644 --- a/cache/abstract.go +++ b/cache/abstract.go @@ -3,6 +3,7 @@ package cache import ( "electricity_bill_calc/global" "fmt" + "math/rand" "strings" "time" @@ -23,9 +24,10 @@ const ( func Cache[T interface{}](key string, value *T, expires time.Duration) error { var err error if expires > 0 { + realExpires := expires + time.Duration(rand.Int63n(60))*time.Second setCmd := global.RedisConn.B().Set(). Key(key).Value(rueidis.JSON(value)). - ExSeconds(int64(expires.Seconds())). + ExSeconds(int64(realExpires.Seconds())). Build() err = global.RedisConn.Do(global.Ctx, setCmd).Error() } else {