1
0
mirror of https://github.com/redis/go-redis.git synced 2025-07-29 17:41:15 +03:00

Change ReceiveMessage to not use Ping

This commit is contained in:
Vladimir Mihailenco
2018-07-24 09:41:14 +03:00
parent c696191b80
commit 9bb7bb3cde
3 changed files with 38 additions and 38 deletions

View File

@ -324,26 +324,18 @@ func ExamplePubSub() {
pubsub := client.Subscribe("mychannel1")
defer pubsub.Close()
// Wait for subscription to be created before publishing message.
subscr, err := pubsub.ReceiveTimeout(time.Second)
if err != nil {
panic(err)
}
fmt.Println(subscr)
// Go channel which receives messages.
ch := pubsub.Channel()
err = client.Publish("mychannel1", "hello").Err()
if err != nil {
panic(err)
}
msg, err := pubsub.ReceiveMessage()
// Publish a message.
err := client.Publish("mychannel1", "hello").Err()
if err != nil {
panic(err)
}
msg := <-ch
fmt.Println(msg.Channel, msg.Payload)
// Output: subscribe: mychannel1
// mychannel1 hello
// Output: mychannel1 hello
}
func ExamplePubSub_Receive() {