Skip to content

Subscribe + sentinel #1

@herkyl

Description

@herkyl

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
		}
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions