From 03e0d4f60f4e2b08bc69d0a842fe9294d72aa7dd Mon Sep 17 00:00:00 2001 From: alvin <34093484@qq.com> Date: Tue, 13 Sep 2022 14:54:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96redis=E5=AE=A2?= =?UTF-8?q?=E6=88=B7=E7=AB=AF=E6=97=B6=E6=94=AF=E6=8C=81IdleCheckFrequency?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E5=8F=AF=E8=87=AA=E5=AE=9A=E4=B9=89=EF=BC=8C?= =?UTF-8?q?=E4=B8=8E=E5=AE=98=E6=96=B9=E8=AE=BE=E5=AE=9A=E4=B8=80=E5=88=86?= =?UTF-8?q?=E9=92=9F=E4=BF=9D=E6=8C=81=E4=B8=80=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cache/redis.go | 50 ++++++++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/cache/redis.go b/cache/redis.go index 8b3b7b2..690e3df 100644 --- a/cache/redis.go +++ b/cache/redis.go @@ -27,32 +27,34 @@ const SYSTEM_CACHE_TIMEOUT_SEASON = 60 * 60 * 24 * 30 * 3 const SYSTEM_CACHE_TIMEOUT_YEAR = 60 * 60 * 24 * 30 * 3 * 12 const ( - defaultMaxIdle = 5 - defaultMaxActive = 0 - defaultTimeoutIdle = 240 - defaultTimeoutConnect = 10000 - defaultTimeoutRead = 5000 - defaultTimeoutWrite = 5000 - defaultAddr = "localhost:6379" - defaultProtocol = "tcp" - defaultRetryThreshold = 5 + defaultMaxIdle = 5 + defaultMaxActive = 0 + defaultTimeoutIdle = 240 + defaultTimeoutConnect = 10000 + defaultTimeoutRead = 5000 + defaultTimeoutWrite = 5000 + defaultAddr = "localhost:6379" + defaultProtocol = "tcp" + defaultRetryThreshold = 5 + defaultIdleCheckFrequency = time.Minute ) const SCRIPT_SETEX = `return redis.call('exists',KEYS[1])<1 and redis.call('setex',KEYS[1],ARGV[2],ARGV[1])` type RedisOptions struct { - MaxIdle int - MaxActive int - Protocol string - Addr string - Password string - DB int - SSLEnabled bool - Expiration time.Duration - TimeoutConnect int - TimeoutRead int - TimeoutWrite int - TimeoutIdle int + MaxIdle int + MaxActive int + Protocol string + Addr string + Password string + DB int + SSLEnabled bool + Expiration time.Duration + TimeoutConnect int + TimeoutRead int + TimeoutWrite int + TimeoutIdle int + IdleCheckFrequency time.Duration } var CTXRedis = context.Background() @@ -77,7 +79,7 @@ func NewGRedis(opts interface{}) (gr *GRedis) { PoolTimeout: 30 * time.Second, IdleTimeout: toI, Password: options.Password, - IdleCheckFrequency: 500 * time.Millisecond, + IdleCheckFrequency: options.IdleCheckFrequency, } if options.SSLEnabled { @@ -132,6 +134,10 @@ func (r *RedisOptions) initDefaults() *RedisOptions { r.Protocol = defaultProtocol } + if r.IdleCheckFrequency == 0 { + r.IdleCheckFrequency = time.Minute + } + return r }