# PSUBSCRIBE

> Subscribe the connection to every channel matching a glob pattern.

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

```
PSUBSCRIBE pattern [pattern ...]
```

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

`PSUBSCRIBE` subscribes the connection to every channel whose name matches one
of the glob patterns, such as `news.*` or `user:[0-9]*`. The pattern syntax is
the same as for [KEYS](https://docs.hotkv.com/commands/keys/index.md). A message on a channel that matches
several of your patterns is delivered once per matching pattern. The
connection enters subscribed mode, as with [SUBSCRIBE](https://docs.hotkv.com/commands/subscribe/index.md).

## Return value

For each pattern, a confirmation:

| Element | Value |
| --- | --- |
| 1 | Bulk string `psubscribe` |
| 2 | Bulk string: the pattern |
| 3 | Integer: the number of channels and patterns this connection is now subscribed to |

Each message then arrives as `pmessage`, the matching pattern, the channel,
and the payload. On RESP3 these are push messages.

## Examples

```
127.0.0.1:6379> PSUBSCRIBE news.*
1) "psubscribe"
2) "news.*"
3) (integer) 1
1) "pmessage"
2) "news.*"
3) "news.sports"
4) "final score 2-1"
```

## Compatibility

Same as Redis 7 and Valkey 8. See [SUBSCRIBE](https://docs.hotkv.com/commands/subscribe/index.md) for the
commands allowed in subscribed mode.

## See also

[PUNSUBSCRIBE](https://docs.hotkv.com/commands/punsubscribe/index.md), [SUBSCRIBE](https://docs.hotkv.com/commands/subscribe/index.md),
[PUBLISH](https://docs.hotkv.com/commands/publish/index.md), [PUBSUB NUMPAT](https://docs.hotkv.com/commands/pubsub-numpat/index.md)