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.

PSUBSCRIBE

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

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.

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"

Same as Redis 7 and Valkey 8. See SUBSCRIBE for the commands allowed in subscribed mode.

PUNSUBSCRIBE, SUBSCRIBE, PUBLISH, PUBSUB NUMPAT