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),如果連接丟失,所有訂閱也會丟失。什麼是更好的方式來恢復丟失的連接和重新訂閱。如何在Redlang(redigo)Pubsub中更好地編寫Golang中的Receive()?
如何創建['redis.Pool'(https://godoc.org/github.com/garyburd/redigo/redis#Pool),其'撥號'功能也訂閱適當的渠道。 –
@ tim-cooper很乾淨的方式。 +1 – kic