What's new in Valkey 9.0? Discover new features and improvements. Read the announcement.

PSUBSCRIBE

Listens for messages published to channels that match one or more patterns.

Usage
PSUBSCRIBE pattern ...
Complexity
O(N) where N is the number of patterns to subscribe to.
Since
2.0.0
ACL Categories
@pubsub, @slow
Command flags
PUBSUB, NOSCRIPT, LOADING, STALE, SENTINEL

Subscribes the client to the given patterns.

Supported glob-style patterns:

  • h?llo subscribes to hello, hallo and hxllo
  • h*llo subscribes to hllo and heeeello
  • h[ae]llo subscribes to hello and hallo, but not hillo

Use \ to escape special characters if you want to match them verbatim.

Once the client enters the subscribed state it is not supposed to issue any other commands, except for additional SUBSCRIBE, SSUBSCRIBE, PSUBSCRIBE, UNSUBSCRIBE, SUNSUBSCRIBE, PUNSUBSCRIBE, PING, RESET and QUIT commands. However, if RESP3 is used (see HELLO) it is possible for a client to issue any commands while in subscribed state.

Note that RESET can be called to exit subscribed state.

For more information, see Pub/sub.

Replies

RESP2

When successful, this command doesn't return anything. Instead, for each pattern, one message with the first element being the string psubscribe is pushed as a confirmation that the command succeeded.

RESP3

When successful, this command doesn't return anything. Instead, for each pattern, one message with the first element being the string psubscribe is pushed as a confirmation that the command succeeded.