Use PSUBSCRIBE to subscribe the current connection to channels by glob-style pattern.
A pattern such as news.* matches every channel that starts with news., including channels created after the subscription, which is what makes patterns useful for topic hierarchies. ? matches a single character and [...] a character class.
Pattern subscriptions are tracked separately from the exact-channel subscriptions made with SUBSCRIBE, and a message that matches several of a connection's patterns is delivered once per matching pattern, so overlapping patterns produce duplicates. Cancel a pattern with PUNSUBSCRIBE, passing exactly the same pattern string.
Syntax#
Arguments#
| Argument | Required | Repeatable | Description |
|---|---|---|---|
<pattern> | Yes | Yes | Glob-style channel pattern. |
Important points#
- This is a connection-oriented command and is available over native Redis TCP, not the stateless REST endpoint.
- Subscription commands require a dedicated TCP connection. In RESP3, subscription events use push replies.
Response#
The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below.
| Protocol | Reply |
|---|---|
| RESP2 | Three-element subscription-state array per pattern |
| RESP3 | Three-element subscription-state push reply per pattern |
Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply.
Examples#
TCP examples use the TLS REDIS_URL from the Upstash console. REST examples use UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN.