w3resource

Redis Pub/Sub: PUBSUB

Redis PUBSUB Command

Redis PUBSUB command is an introspection command that allows to inspecting the state of the Pub/Sub subsystem. It is composed of subcommands that are documented separately.

Here are some common uses and scenarios for the "PUBSUB" command:

  • Channel Inspection: Provides information about active channels, including the number of subscribers, helping monitor channel activity.
  • Subscription Management: Lists patterns and channels that clients are currently subscribed to, aiding in managing and debugging subscriptions.
  • Client Insights: Retrieves information about clients connected to the Redis server and their subscriptions, useful for diagnostics and optimization.
  • Traffic Analysis: Helps analyze messaging traffic and understand the distribution of messages across channels and patterns.

Syntax:

PUBSUB subcommand [argument [argument ...]]

Following listing shows some supported patterens in redis

  • 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

Available since

2.8.0.

Return Value

Array reply, a list of active channels.

Return Value Type

Array

Example: Redis PUBSUB

redis 127.0.0.1:6379> PUBSUB CHANNELS
(empty list or set)


Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/redis/redis-pubsub-subcommand.php