PSUBSCRIBE
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.
Return value
Section titled “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
Section titled “Examples”127.0.0.1:6379> PSUBSCRIBE news.*1) "psubscribe"2) "news.*"3) (integer) 11) "pmessage"2) "news.*"3) "news.sports"4) "final score 2-1"Compatibility
Section titled “Compatibility”Same as Redis 7 and Valkey 8. See SUBSCRIBE for the commands allowed in subscribed mode.
See also
Section titled “See also”Was this page helpful?
Thanks for the feedback.