mirror of https://github.com/go-redis/redis.git
Add ConnChecker to customize conn health check
This commit is contained in:
parent
4cf03dbd39
commit
b802a3e5e3
|
@ -68,6 +68,7 @@ type Options struct {
|
||||||
MaxActiveConns int
|
MaxActiveConns int
|
||||||
ConnMaxIdleTime time.Duration
|
ConnMaxIdleTime time.Duration
|
||||||
ConnMaxLifetime time.Duration
|
ConnMaxLifetime time.Duration
|
||||||
|
ConnChecker func(net.Conn) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type lastDialErrorWrap struct {
|
type lastDialErrorWrap struct {
|
||||||
|
@ -513,6 +514,12 @@ func (p *ConnPool) isHealthyConn(cn *Conn) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if p.cfg.ConnChecker != nil {
|
||||||
|
if err := p.cfg.ConnChecker(cn.netConn); err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cn.SetUsedAt(now)
|
cn.SetUsedAt(now)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,6 +139,9 @@ type Options struct {
|
||||||
// Default is to not close idle connections.
|
// Default is to not close idle connections.
|
||||||
ConnMaxLifetime time.Duration
|
ConnMaxLifetime time.Duration
|
||||||
|
|
||||||
|
// ConnChecker checks the health of a connection before returning it to the client.
|
||||||
|
ConnChecker func(net.Conn) error
|
||||||
|
|
||||||
// TLS Config to use. When set, TLS will be negotiated.
|
// TLS Config to use. When set, TLS will be negotiated.
|
||||||
TLSConfig *tls.Config
|
TLSConfig *tls.Config
|
||||||
|
|
||||||
|
@ -520,5 +523,6 @@ func newConnPool(
|
||||||
MaxActiveConns: opt.MaxActiveConns,
|
MaxActiveConns: opt.MaxActiveConns,
|
||||||
ConnMaxIdleTime: opt.ConnMaxIdleTime,
|
ConnMaxIdleTime: opt.ConnMaxIdleTime,
|
||||||
ConnMaxLifetime: opt.ConnMaxLifetime,
|
ConnMaxLifetime: opt.ConnMaxLifetime,
|
||||||
|
ConnChecker: opt.ConnChecker,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue