mirror of https://github.com/go-redis/redis.git
Cleanup
This commit is contained in:
parent
5c041b4083
commit
0064936c5b
26
sentinel.go
26
sentinel.go
|
@ -305,16 +305,27 @@ func (c *sentinelFailover) switchMaster(addr string) {
|
||||||
func (c *sentinelFailover) setSentinel(sentinel *SentinelClient) {
|
func (c *sentinelFailover) setSentinel(sentinel *SentinelClient) {
|
||||||
c.discoverSentinels(sentinel)
|
c.discoverSentinels(sentinel)
|
||||||
c.sentinel = sentinel
|
c.sentinel = sentinel
|
||||||
go c.listen(sentinel)
|
|
||||||
|
c.pubsub = sentinel.Subscribe("+switch-master")
|
||||||
|
go c.listen(c.pubsub)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *sentinelFailover) closeSentinel() error {
|
func (c *sentinelFailover) closeSentinel() error {
|
||||||
if err := c.pubsub.Close(); err != nil {
|
var firstErr error
|
||||||
return err
|
|
||||||
|
err := c.pubsub.Close()
|
||||||
|
if err != nil && firstErr == err {
|
||||||
|
firstErr = err
|
||||||
|
}
|
||||||
|
c.pubsub = nil
|
||||||
|
|
||||||
|
err = c.sentinel.Close()
|
||||||
|
if err != nil && firstErr == err {
|
||||||
|
firstErr = err
|
||||||
}
|
}
|
||||||
err := c.sentinel.Close()
|
|
||||||
c.sentinel = nil
|
c.sentinel = nil
|
||||||
return err
|
|
||||||
|
return firstErr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *sentinelFailover) discoverSentinels(sentinel *SentinelClient) {
|
func (c *sentinelFailover) discoverSentinels(sentinel *SentinelClient) {
|
||||||
|
@ -339,9 +350,8 @@ func (c *sentinelFailover) discoverSentinels(sentinel *SentinelClient) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *sentinelFailover) listen(sentinel *SentinelClient) {
|
func (c *sentinelFailover) listen(pubsub *PubSub) {
|
||||||
c.pubsub = sentinel.Subscribe("+switch-master")
|
ch := pubsub.Channel()
|
||||||
ch := c.pubsub.Channel()
|
|
||||||
for {
|
for {
|
||||||
msg, ok := <-ch
|
msg, ok := <-ch
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|
Loading…
Reference in New Issue