-
Notifications
You must be signed in to change notification settings - Fork 13
Pubsub
Tam. Nguyen Duc edited this page May 29, 2014
·
1 revision
Publish message to a channel is easy, you can use gore.Command to issue a PUBLISH over a connection, or use gore.Publish method:
gore.Publish(conn, "touhou", "Hello!")
To handle subscriptions, you should allocate a dedicated connection and assign it to gore.Subscriptions:
subs := gore.NewSubscriptions(conn)
subs.Subscribe("test")
subs.PSubscribe("tou*")
To receive messages, the subcriber should spawn a new goroutine and use Subscriptions Message channel:
go func() {
for message := range subs.Message() {
if message == nil {
break
}
fmt.Println("Got message from %s, originate from %s: %s", message.Channel, message.OriginalChannel, message.Message)
}
}()