From a47799f02c032371a96a71900425166187ee0c80 Mon Sep 17 00:00:00 2001 From: Rob McColl Date: Tue, 27 Nov 2018 16:13:30 -0500 Subject: [PATCH] doc: add info about Receive call after Subscribe --- redis.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/redis.go b/redis.go index 92a07fc6..c8b14ab6 100644 --- a/redis.go +++ b/redis.go @@ -460,6 +460,30 @@ func (c *Client) pubSub() *PubSub { // Subscribe subscribes the client to the specified channels. // Channels can be omitted to create empty subscription. +// Note that this method does not wait on a response from Redis, so the +// subscription may not be active immediately. To force the connection to wait, +// you may call the Receive() method on the returned *PubSub like so: +// +// sub := client.Subscribe(queryResp) +// iface, err := sub.Receive() +// if err != nil { +// // handle error +// } +// +// // Should be *Subscription, but others are possible if other actions have been +// // taken on sub since it was created. +// switch iface.(type) { +// case *Subscription: +// // subscribe succeeded +// case *Message: +// // received first message +// case *Pong: +// // pong received +// default: +// // handle error +// } +// +// ch := sub.Channel() func (c *Client) Subscribe(channels ...string) *PubSub { pubsub := c.pubSub() if len(channels) > 0 {