forked from mirror/redis
Doc
This commit is contained in:
parent
84163af3c1
commit
18c1db9466
|
@ -13,6 +13,9 @@ import (
|
||||||
// PubSub implements Pub/Sub commands as described in
|
// PubSub implements Pub/Sub commands as described in
|
||||||
// http://redis.io/topics/pubsub. It's NOT safe for concurrent use by
|
// http://redis.io/topics/pubsub. It's NOT safe for concurrent use by
|
||||||
// multiple goroutines.
|
// multiple goroutines.
|
||||||
|
//
|
||||||
|
// PubSub automatically resubscribes to the channels and patterns
|
||||||
|
// when Redis becomes unavailable.
|
||||||
type PubSub struct {
|
type PubSub struct {
|
||||||
base baseClient
|
base baseClient
|
||||||
|
|
||||||
|
@ -138,7 +141,8 @@ func (c *PubSub) _subscribe(cn *pool.Conn, redisCmd string, channels ...string)
|
||||||
return writeCmd(cn, cmd)
|
return writeCmd(cn, cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Subscribes the client to the specified channels.
|
// Subscribes the client to the specified channels. It returns
|
||||||
|
// empty subscription if there are no channels.
|
||||||
func (c *PubSub) Subscribe(channels ...string) error {
|
func (c *PubSub) Subscribe(channels ...string) error {
|
||||||
c.subMu.Lock()
|
c.subMu.Lock()
|
||||||
c.channels = appendIfNotExists(c.channels, channels...)
|
c.channels = appendIfNotExists(c.channels, channels...)
|
||||||
|
@ -146,7 +150,8 @@ func (c *PubSub) Subscribe(channels ...string) error {
|
||||||
return c.subscribe("subscribe", channels...)
|
return c.subscribe("subscribe", channels...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Subscribes the client to the given patterns.
|
// Subscribes the client to the given patterns. It returns
|
||||||
|
// empty subscription if there are no patterns.
|
||||||
func (c *PubSub) PSubscribe(patterns ...string) error {
|
func (c *PubSub) PSubscribe(patterns ...string) error {
|
||||||
c.subMu.Lock()
|
c.subMu.Lock()
|
||||||
c.patterns = appendIfNotExists(c.patterns, patterns...)
|
c.patterns = appendIfNotExists(c.patterns, patterns...)
|
||||||
|
|
Loading…
Reference in New Issue