Back to Redis

PSUBSCRIBE

content/commands/psubscribe.md

latest2.2 KB
Original Source

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]({{< relref "/commands/subscribe" >}}), [SSUBSCRIBE]({{< relref "/commands/ssubscribe" >}}), PSUBSCRIBE, [UNSUBSCRIBE]({{< relref "/commands/unsubscribe" >}}), [SUNSUBSCRIBE]({{< relref "/commands/sunsubscribe" >}}), [PUNSUBSCRIBE]({{< relref "/commands/punsubscribe" >}}), [PING]({{< relref "/commands/ping" >}}), [RESET]({{< relref "/commands/reset" >}}) and [QUIT]({{< relref "/commands/quit" >}}) commands. However, if RESP3 is used (see [HELLO]({{< relref "/commands/hello" >}})) it is possible for a client to issue any commands while in subscribed state.

For more information, see [Pub/sub]({{< relref "/develop/pubsub" >}}).

Behavior change history

  • >= 6.2.0: [RESET]({{< relref "/commands/reset" >}}) can be called to exit subscribed state.

Redis Software and Redis Cloud compatibility

| Redis Software | Redis Cloud | <span style="min-width: 9em; display: table-cell">Notes</span> | |:----------------------|:-----------------|:------| | <span title="Supported">✅ Standard</span> <span title="Supported"><nobr>✅ Active-Active</nobr></span> | <span title="Supported">✅ Standard</span> <span title="Supported"><nobr>✅ Active-Active</nobr></span> | |

Return information

{{< multitabs id="psubscribe-return-info" tab1="RESP2" tab2="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.

-tab-sep-

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.

{{< /multitabs >}}