mirror of
https://github.com/astaxie/beego.git
synced 2024-11-25 14:10:55 +00:00
Merge pull request #4033 from jianzhiyao/develop
make redis client idle timeout configurable
This commit is contained in:
commit
ad68e8d866
14
cache/redis/redis.go
vendored
14
cache/redis/redis.go
vendored
@ -55,6 +55,9 @@ type Cache struct {
|
|||||||
key string
|
key string
|
||||||
password string
|
password string
|
||||||
maxIdle int
|
maxIdle int
|
||||||
|
|
||||||
|
//the timeout to a value less than the redis server's timeout.
|
||||||
|
timeout time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewRedisCache create new redis cache with default collection name.
|
// NewRedisCache create new redis cache with default collection name.
|
||||||
@ -211,12 +214,21 @@ func (rc *Cache) StartAndGC(config string) error {
|
|||||||
if _, ok := cf["maxIdle"]; !ok {
|
if _, ok := cf["maxIdle"]; !ok {
|
||||||
cf["maxIdle"] = "3"
|
cf["maxIdle"] = "3"
|
||||||
}
|
}
|
||||||
|
if _, ok := cf["timeout"]; !ok {
|
||||||
|
cf["timeout"] = "180s"
|
||||||
|
}
|
||||||
rc.key = cf["key"]
|
rc.key = cf["key"]
|
||||||
rc.conninfo = cf["conn"]
|
rc.conninfo = cf["conn"]
|
||||||
rc.dbNum, _ = strconv.Atoi(cf["dbNum"])
|
rc.dbNum, _ = strconv.Atoi(cf["dbNum"])
|
||||||
rc.password = cf["password"]
|
rc.password = cf["password"]
|
||||||
rc.maxIdle, _ = strconv.Atoi(cf["maxIdle"])
|
rc.maxIdle, _ = strconv.Atoi(cf["maxIdle"])
|
||||||
|
|
||||||
|
if v, err := time.ParseDuration(cf["timeout"]); err == nil {
|
||||||
|
rc.timeout = v
|
||||||
|
} else {
|
||||||
|
rc.timeout = 180 * time.Second
|
||||||
|
}
|
||||||
|
|
||||||
rc.connectInit()
|
rc.connectInit()
|
||||||
|
|
||||||
c := rc.p.Get()
|
c := rc.p.Get()
|
||||||
@ -250,7 +262,7 @@ func (rc *Cache) connectInit() {
|
|||||||
// initialize a new pool
|
// initialize a new pool
|
||||||
rc.p = &redis.Pool{
|
rc.p = &redis.Pool{
|
||||||
MaxIdle: rc.maxIdle,
|
MaxIdle: rc.maxIdle,
|
||||||
IdleTimeout: 180 * time.Second,
|
IdleTimeout: rc.timeout,
|
||||||
Dial: dialFunc,
|
Dial: dialFunc,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user