mirror of
https://github.com/redis/go-redis.git
synced 2025-07-28 06:42:00 +03:00
Add reaper that closes idle connections to the cluster.
This commit is contained in:
15
cluster.go
15
cluster.go
@ -42,6 +42,7 @@ func NewClusterClient(opt *ClusterOptions) (*ClusterClient, error) {
|
||||
}
|
||||
client.commandable.process = client.process
|
||||
client.reloadIfDue()
|
||||
go client.reaper(time.NewTicker(5 * time.Minute))
|
||||
return client, nil
|
||||
}
|
||||
|
||||
@ -220,6 +221,20 @@ func (c *ClusterClient) update(infos []ClusterSlotInfo) {
|
||||
}
|
||||
}
|
||||
|
||||
// reaper closes idle connections to the cluster.
|
||||
func (c *ClusterClient) reaper(ticker *time.Ticker) {
|
||||
for _ = range ticker.C {
|
||||
for _, client := range c.conns {
|
||||
pool := client.connPool
|
||||
// pool.First removes idle connections from the pool for us. So
|
||||
// just put returned connection back.
|
||||
if cn := pool.First(); cn != nil {
|
||||
pool.Put(cn)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
var errNoAddrs = errors.New("redis: no addresses")
|
||||
|
Reference in New Issue
Block a user