1
0
mirror of https://github.com/redis/go-redis.git synced 2025-07-28 06:42:00 +03:00

pubsub: add PING support.

This commit is contained in:
Vladimir Mihailenco
2015-07-11 13:12:47 +03:00
parent 39c9dc2665
commit f901321d84
3 changed files with 91 additions and 40 deletions

View File

@ -2,7 +2,6 @@ package redis_test
import (
"fmt"
"net"
"strconv"
"sync"
"time"
@ -179,14 +178,14 @@ func ExamplePubSub() {
panic(err)
}
for {
for i := 0; i < 4; i++ {
msgi, err := pubsub.ReceiveTimeout(100 * time.Millisecond)
if err != nil {
if neterr, ok := err.(net.Error); ok && neterr.Timeout() {
// There are no more messages to process. Stop.
break
err := pubsub.Ping("")
if err != nil {
panic(err)
}
panic(err)
continue
}
switch msg := msgi.(type) {
@ -194,6 +193,8 @@ func ExamplePubSub() {
fmt.Println(msg.Kind, msg.Channel)
case *redis.Message:
fmt.Println(msg.Channel, msg.Payload)
case *redis.Pong:
fmt.Println(msg)
default:
panic(fmt.Sprintf("unknown message: %#v", msgi))
}
@ -201,6 +202,7 @@ func ExamplePubSub() {
// Output: subscribe mychannel
// mychannel hello
// Pong
}
func ExampleScript() {