mirror of
https://github.com/redis/go-redis.git
synced 2025-04-19 07:22:17 +03:00
Add PubSub support to Ring
This commit is contained in:
parent
313a8d7fab
commit
346c00d485
28
ring.go
28
ring.go
@ -177,6 +177,34 @@ func (c *Ring) PoolStats() *PoolStats {
|
|||||||
return &acc
|
return &acc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Subscribe subscribes the client to the specified channels.
|
||||||
|
func (c *Ring) Subscribe(channels ...string) *PubSub {
|
||||||
|
if len(channels) == 0 {
|
||||||
|
panic("at least one channel is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
shard, err := c.shardByKey(channels[0])
|
||||||
|
if err != nil {
|
||||||
|
// TODO: return PubSub with sticky error
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return shard.Client.Subscribe(channels...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// PSubscribe subscribes the client to the given patterns.
|
||||||
|
func (c *Ring) PSubscribe(channels ...string) *PubSub {
|
||||||
|
if len(channels) == 0 {
|
||||||
|
panic("at least one channel is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
shard, err := c.shardByKey(channels[0])
|
||||||
|
if err != nil {
|
||||||
|
// TODO: return PubSub with sticky error
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return shard.Client.PSubscribe(channels...)
|
||||||
|
}
|
||||||
|
|
||||||
// ForEachShard concurrently calls the fn on each live shard in the ring.
|
// ForEachShard concurrently calls the fn on each live shard in the ring.
|
||||||
// It returns the first error if any.
|
// It returns the first error if any.
|
||||||
func (c *Ring) ForEachShard(fn func(client *Client) error) error {
|
func (c *Ring) ForEachShard(fn func(client *Client) error) error {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user