Skip to content

Ask the HotKV docs

Answers come only from these docs and can be wrong; check the linked pages before you rely on them.

PUNSUBSCRIBE

Last updated
PUNSUBSCRIBE [pattern [pattern ...]]
Group
Pub/Sub
Complexity
O(N) for N patterns
Arity
-1 (at least 1 words, counting the command name)
Flags
pubsub
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; 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.

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.

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

Same as Redis 7 and Valkey 8.

PSUBSCRIBE, UNSUBSCRIBE