Attempt to Close Sentinel when the cluster is Closed.

This commit is contained in:
devine 2024-04-12 16:35:08 +08:00
parent 6833d2f8e1
commit 7462713440
2 changed files with 8 additions and 3 deletions

View File

@ -62,6 +62,8 @@ type ClusterOptions struct {
OnConnect func(ctx context.Context, cn *Conn) error
OnClose func() error
Protocol int
Username string
Password string
@ -868,7 +870,6 @@ func NewClusterClient(opt *ClusterOptions) *ClusterClient {
c.state = newClusterStateHolder(c.loadState)
c.cmdsInfoCache = newCmdsInfoCache(c.cmdsInfo)
c.cmdable = c.Process
c.initHooks(hooks{
dial: nil,
process: c.process,
@ -895,7 +896,11 @@ func (c *ClusterClient) ReloadState(ctx context.Context) {
// It is rare to Close a ClusterClient, as the ClusterClient is meant
// to be long-lived and shared between many goroutines.
func (c *ClusterClient) Close() error {
return c.nodes.Close()
err := c.nodes.Close()
if c.opt.OnClose != nil && err == nil {
err = c.opt.OnClose()
}
return err
}
// Do create a Cmd from the args and processes the cmd.

View File

@ -825,7 +825,7 @@ func NewFailoverClusterClient(failoverOpt *FailoverOptions) *ClusterClient {
}
return slots, nil
}
opt.OnClose = failover.Close
c := NewClusterClient(opt)
failover.mu.Lock()