Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscribe + sentinel #1

Open
herkyl opened this issue Jul 7, 2018 · 3 comments
Open

Subscribe + sentinel #1

herkyl opened this issue Jul 7, 2018 · 3 comments

Comments

@herkyl
Copy link

herkyl commented Jul 7, 2018

How do I keep a PubSubConn alive when Sentinel is switching masters?

My current code panics right after the master goes down:

func NewRedisDataSub(pool *redis.Pool, subCh chan *msg.RedisMessage) {
	c := pool.Get()
	pubsub := redis.PubSubConn{Conn: c}
	pubsub.Subscribe("data")
	defer func() {
		panic("Exited NewRedisDataSub")
	}()
	for {
		switch v := pubsub.Receive().(type) {
		case redis.Message:
			// Handle message
		case error:
			log.Error(v)
			return
		}
	}
}
@FZambia
Copy link
Owner

FZambia commented Jul 8, 2018

Hello. You can just restart your pubsub routine after error. Get new connection from pool, subscribe it to channel.

@herkyl
Copy link
Author

herkyl commented Jul 8, 2018

Thanks for the prompt reply @FZambia!
How do I then figure out when all of the masters are down? I need to panic when pubsub stops working.

@FZambia
Copy link
Owner

FZambia commented Jul 9, 2018

Hmm, I am not ready to answer on this question at moment because I don't know for sure can we somehow distinguish case when all masters are down - need investigation on how Sentinel behaves.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants