SUnsubscribe unsubscribes the client from the given shard channels, or from all of them if none is given.
(ctx context.Context, channels ...string)
| 315 | // SUnsubscribe unsubscribes the client from the given shard channels, |
| 316 | // or from all of them if none is given. |
| 317 | func (c *PubSub) SUnsubscribe(ctx context.Context, channels ...string) error { |
| 318 | c.mu.Lock() |
| 319 | defer c.mu.Unlock() |
| 320 | |
| 321 | if len(channels) > 0 { |
| 322 | for _, channel := range channels { |
| 323 | delete(c.schannels, channel) |
| 324 | } |
| 325 | } else { |
| 326 | // Unsubscribe from all channels. |
| 327 | clear(c.schannels) |
| 328 | } |
| 329 | |
| 330 | err := c.subscribe(ctx, "sunsubscribe", channels...) |
| 331 | return err |
| 332 | } |
| 333 | |
| 334 | func (c *PubSub) subscribe(ctx context.Context, redisCmd string, channels ...string) error { |
| 335 | cn, err := c.conn(ctx, channels) |