From 7fd80e6aa1da4ed58eec91c78d9312e81456b382 Mon Sep 17 00:00:00 2001 From: Pieter Callewaert Date: Tue, 26 Dec 2017 11:21:39 +0100 Subject: [PATCH 1/2] feat(redis.go): make MaxIdle configurable --- cache/redis/redis.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cache/redis/redis.go b/cache/redis/redis.go index 1da22480..603ade7e 100644 --- a/cache/redis/redis.go +++ b/cache/redis/redis.go @@ -53,6 +53,7 @@ type Cache struct { dbNum int key string password string + maxIdle int } // NewRedisCache create new redis cache with default collection name. @@ -169,10 +170,14 @@ func (rc *Cache) StartAndGC(config string) error { if _, ok := cf["password"]; !ok { cf["password"] = "" } + if _, ok := cf["maxIdle"]; !ok { + cf["maxIdle"] = "" + } rc.key = cf["key"] rc.conninfo = cf["conn"] rc.dbNum, _ = strconv.Atoi(cf["dbNum"]) rc.password = cf["password"] + rc.maxIdle, _ = strconv.Atoi(cf["maxIdle"]) rc.connectInit() @@ -206,7 +211,7 @@ func (rc *Cache) connectInit() { } // initialize a new pool rc.p = &redis.Pool{ - MaxIdle: 3, + MaxIdle: rc.maxIdle, IdleTimeout: 180 * time.Second, Dial: dialFunc, } From 59fd3952b7769d3c50ef45e4ecf36c12e4d01508 Mon Sep 17 00:00:00 2001 From: Pieter Callewaert Date: Tue, 26 Dec 2017 11:43:04 +0100 Subject: [PATCH 2/2] bug: restore the default value --- cache/redis/redis.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cache/redis/redis.go b/cache/redis/redis.go index 603ade7e..c5eb8744 100644 --- a/cache/redis/redis.go +++ b/cache/redis/redis.go @@ -171,7 +171,7 @@ func (rc *Cache) StartAndGC(config string) error { cf["password"] = "" } if _, ok := cf["maxIdle"]; !ok { - cf["maxIdle"] = "" + cf["maxIdle"] = "3" } rc.key = cf["key"] rc.conninfo = cf["conn"]