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 {