c := redisPool.Get() psc := redis.PubSubConn{c} psc.PSubscribe("aa*") for { switch v := psc.Receive().(type) { case redis.Subscription: fmt.Printf("%s: %s %d\n", v.Channel, v.Kind, v.Count) case redis.Message://单个订阅subscribe fmt.Printf("%s: message: %s\n", v.Channel, v.Data) case redis.PMessage://模式订阅psubscribe fmt.Printf("PMessage: %s %s %s\n", v.Pattern, v.Channel, v.Data) case error: return } }
有疑问加站长微信联系(非本文作者)