mirror of https://github.com/go-redis/redis.git
Merge pull request #899 from fanatic/master
Cleanup sentinel pubsub on close
This commit is contained in:
commit
5c041b4083
10
sentinel.go
10
sentinel.go
|
@ -176,6 +176,7 @@ type sentinelFailover struct {
|
||||||
masterName string
|
masterName string
|
||||||
_masterAddr string
|
_masterAddr string
|
||||||
sentinel *SentinelClient
|
sentinel *SentinelClient
|
||||||
|
pubsub *PubSub
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *sentinelFailover) Close() error {
|
func (c *sentinelFailover) Close() error {
|
||||||
|
@ -308,6 +309,9 @@ func (c *sentinelFailover) setSentinel(sentinel *SentinelClient) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *sentinelFailover) closeSentinel() error {
|
func (c *sentinelFailover) closeSentinel() error {
|
||||||
|
if err := c.pubsub.Close(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
err := c.sentinel.Close()
|
err := c.sentinel.Close()
|
||||||
c.sentinel = nil
|
c.sentinel = nil
|
||||||
return err
|
return err
|
||||||
|
@ -336,10 +340,8 @@ func (c *sentinelFailover) discoverSentinels(sentinel *SentinelClient) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *sentinelFailover) listen(sentinel *SentinelClient) {
|
func (c *sentinelFailover) listen(sentinel *SentinelClient) {
|
||||||
pubsub := sentinel.Subscribe("+switch-master")
|
c.pubsub = sentinel.Subscribe("+switch-master")
|
||||||
defer pubsub.Close()
|
ch := c.pubsub.Channel()
|
||||||
|
|
||||||
ch := pubsub.Channel()
|
|
||||||
for {
|
for {
|
||||||
msg, ok := <-ch
|
msg, ok := <-ch
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|
Loading…
Reference in New Issue