mirror of
https://github.com/redis/go-redis.git
synced 2025-04-19 07:22:17 +03:00
Allow creating PubSub without channels.
This commit is contained in:
parent
754e4ed906
commit
c939d2283e
16
redis.go
16
redis.go
@ -359,11 +359,23 @@ func (c *Client) pubSub() *PubSub {
|
||||
// Subscribe subscribes the client to the specified channels.
|
||||
func (c *Client) Subscribe(channels ...string) (*PubSub, error) {
|
||||
pubsub := c.pubSub()
|
||||
return pubsub, pubsub.Subscribe(channels...)
|
||||
if len(channels) > 0 {
|
||||
if err := pubsub.Subscribe(channels...); err != nil {
|
||||
pubsub.Close()
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return pubsub, nil
|
||||
}
|
||||
|
||||
// PSubscribe subscribes the client to the given patterns.
|
||||
func (c *Client) PSubscribe(channels ...string) (*PubSub, error) {
|
||||
pubsub := c.pubSub()
|
||||
return pubsub, pubsub.PSubscribe(channels...)
|
||||
if len(channels) > 0 {
|
||||
if err := pubsub.PSubscribe(channels...); err != nil {
|
||||
pubsub.Close()
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return pubsub, nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user