1
0
mirror of https://github.com/redis/go-redis.git synced 2025-07-28 06:42:00 +03:00

Fix FailoverClient to close connection to Sentinel. Fixes races build.

This commit is contained in:
Vladimir Mihailenco
2016-03-09 15:14:01 +02:00
parent 0db1d730c8
commit 27635bbe4e
4 changed files with 80 additions and 54 deletions

View File

@ -13,6 +13,8 @@ var Logger = log.New(os.Stderr, "redis: ", log.LstdFlags)
type baseClient struct {
connPool pool
opt *Options
onClose func() error // hook called when client is closed
}
func (c *baseClient) String() string {
@ -83,7 +85,16 @@ func (c *baseClient) process(cmd Cmder) {
// It is rare to Close a Client, as the Client is meant to be
// long-lived and shared between many goroutines.
func (c *baseClient) Close() error {
return c.connPool.Close()
var retErr error
if c.onClose != nil {
if err := c.onClose(); err != nil && retErr == nil {
retErr = err
}
}
if err := c.connPool.Close(); err != nil && retErr == nil {
retErr = err
}
return retErr
}
//------------------------------------------------------------------------------
@ -186,8 +197,10 @@ type Client struct {
func newClient(opt *Options, pool pool) *Client {
base := baseClient{opt: opt, connPool: pool}
return &Client{
baseClient: base,
commandable: commandable{process: base.process},
baseClient: base,
commandable: commandable{
process: base.process,
},
}
}