psc := redis.PubSubConn{c}
psc.Subscribe("example")
func Receive() {
for {
switch v := psc.Receive().(type) {
case redis.Message:
fmt.Printf("%s: message: %s\n", v.Channel, v.Data)
case redis.Subscription:
fmt.Printf("%s: %s %d\n", v.Channel, v.Kind, v.Count)
case error:
return v
}
}
}
在上面的代码中(取自Redigo doc),如果连接丢失,所有订阅也会丢失。从丢失的连接中恢复并重新订阅的更好方法是什么。