# UNSUBSCRIBE

> Unsubscribe the connection from Pub/Sub channels.

URL: https://docs.hotkv.com/commands/unsubscribe/

```
UNSUBSCRIBE [channel [channel ...]]
```

- Group: Pub/Sub
- Complexity: O(N) for N channels
- HotKV Cloud: all plans
- On-Premise: no license needed

`UNSUBSCRIBE` stops delivery from the given channels. Without arguments it
unsubscribes from every channel the connection subscribed to with
[SUBSCRIBE](https://docs.hotkv.com/commands/subscribe/index.md). Pattern subscriptions
([PSUBSCRIBE](https://docs.hotkv.com/commands/psubscribe/index.md)) and shard channel subscriptions
([SSUBSCRIBE](https://docs.hotkv.com/commands/ssubscribe/index.md)) are not affected.

## Return value

One confirmation per channel removed (or per channel named):

| Element | Value |
| --- | --- |
| 1 | Bulk string `unsubscribe` |
| 2 | Bulk string: the channel |
| 3 | Integer: the number of channels and patterns still subscribed |

When called without arguments and the connection has no channel
subscriptions, a single confirmation is sent with a nil channel. On RESP3 the
confirmations are push messages.

## Examples

```
127.0.0.1:6379> SUBSCRIBE news alerts
1) "subscribe"
2) "news"
3) (integer) 1
1) "subscribe"
2) "alerts"
3) (integer) 2
127.0.0.1:6379> UNSUBSCRIBE news
1) "unsubscribe"
2) "news"
3) (integer) 1
```

## Compatibility

Same as Redis 7 and Valkey 8.

## See also

[SUBSCRIBE](https://docs.hotkv.com/commands/subscribe/index.md), [PUNSUBSCRIBE](https://docs.hotkv.com/commands/punsubscribe/index.md),
[SUNSUBSCRIBE](https://docs.hotkv.com/commands/sunsubscribe/index.md)