Upstash Documentation

PUNSUBSCRIBE

Unsubscribe from patterns.
2 min read

Use PUNSUBSCRIBE to cancel pattern subscriptions of the current connection.

With no arguments the connection unsubscribes from every pattern it registered, otherwise only from the patterns named, which must be given exactly as they were passed to PSUBSCRIBE, since patterns are matched literally here and not expanded. The server sends one confirmation per pattern with the number of subscriptions still active.

Exact-channel subscriptions are not affected; cancel those with UNSUBSCRIBE.

Syntax#

Arguments#

ArgumentRequiredRepeatableDescription
<pattern>NoYesGlob-style channel pattern; omit to unsubscribe from all patterns.

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.

ProtocolReply
RESP2Three-element subscription-state array per pattern
RESP3Three-element subscription-state push reply per pattern
Note

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.

Redis CLI
ioredis
node-redis
redis-py
go-redis
jedis
redis-rs