# PUNSUBSCRIBE

> Remove pattern subscriptions from the connection.

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

```
PUNSUBSCRIBE [pattern [pattern ...]]
```

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

`PUNSUBSCRIBE` removes the given pattern subscriptions. The pattern must be
written exactly as it was passed to [PSUBSCRIBE](https://docs.hotkv.com/commands/psubscribe/index.md); it is
not matched against other patterns. Without arguments it removes every pattern
subscription of the connection, and leaves channel and shard channel
subscriptions alone.

## Return value

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

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

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

## Examples

```
127.0.0.1:6379> PSUBSCRIBE news.* alerts.*
1) "psubscribe"
2) "news.*"
3) (integer) 1
1) "psubscribe"
2) "alerts.*"
3) (integer) 2
127.0.0.1:6379> PUNSUBSCRIBE alerts.*
1) "punsubscribe"
2) "alerts.*"
3) (integer) 1
```

## Compatibility

Same as Redis 7 and Valkey 8.

## See also

[PSUBSCRIBE](https://docs.hotkv.com/commands/psubscribe/index.md), [UNSUBSCRIBE](https://docs.hotkv.com/commands/unsubscribe/index.md)