Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What is the function of Pub/Sub in Redis

Shulou Source: shulou.com Published: 2022-06-02 05:48:08 10月03日 Update

What is the role of Pub/Sub in Redis? I believe many inexperienced people don't know what to do about it. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

Redis publishes commands related to the subscription model.

PSUBSCRIBE

Earliest available version: 2.0.0

Time complexity: O (N), N is the number of subscribed clients.

A client that subscribes to a given rule in the following forms:

H?llo subscribes to hello,hallo, hxllo, etc.

H*llo subscribes to hllo, heeeello, etc.

H [ae] subscribe to hello and hallo, but not to hillo

If you want to match verbatim, use\ to escape special characters.

PUBLISH

Earliest available version: 2.0.0

Time complexity: O (NumberM), N is the number of subscribed clients, M is the total number of subscriptions

Post a message to the specified channel.

PUBSUB

Earliest available version: 2.8.0

Time complexity: O (N), N is the number of active channels

This command is used to check the status of the Pub/Sub subsystem.

1PUBSUB CHANNELS [pattern]

List the currently active channels (with at least one subscriber). However, if you do not specify pattern, all channels are listed.

1PUBSUB NUMSUB [channel-1... Channel-N]

Returns the subscriber of the specified channel.

1PUBSUB NUMPAT

Returns the number of subscriptions for the specified pattern (executed using the PSUBSCRIBE command)

PUNSUBSCRIBE

Earliest available version: 2.0.0

Time complexity: O (NumberM), N is the number of subscriptions that have been subscribed by clients that match rules, and M is the total number of subscriptions to matching rules in the system

Usage: PUNSUBSCRIBE [pattern [pattern …]]

Unsubscribe all channels that match the rules, or unsubscribe all channels if no rules are specified.

SUBSCRIBE

Earliest available version: 2.0.0

Time complexity: O (N), N is the number of subscription channels

Subscribe to the specified channel to the client.

After reading the above, have you mastered the role of Pub/Sub in Redis? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Tags: Subscriptions channels complexity clients clients times versions rules commands actions content totals quantities methods more patterns subscribers questions special Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Shulou Technology NVidia macOS Xiaomi