What's new in Valkey 9.0? Discover new features and improvements. Read the announcement.
PUBSUB NUMSUB
Returns a count of subscribers to channels.
Usage
PUBSUB NUMSUB [channel ...]
Complexity
O(N) for the NUMSUB subcommand, where N is the number of requested channels
Since
2.8.0
ACL Categories
@pubsub, @slow
Command flags
PUBSUB, LOADING, STALE
Returns the number of subscribers (exclusive of clients subscribed to patterns) for the specified channels.
Note that it is valid to call this command without channels. In this case it will just return an empty list.
Cluster note: in a Valkey Cluster clients can subscribe to every node, and can also publish to every other node. The cluster will make sure that published messages are forwarded as needed. That said, the replies from PUBSUB in a cluster only report information from the node's Pub/Sub context, rather than the entire cluster.
Replies
RESP2
Array reply: the number of subscribers per channel, each even element (including the 0th) is channel name, each odd element is the number of subscribers
RESP3
Array reply: the number of subscribers per channel, each even element (including the 0th) is channel name, each odd element is the number of subscribers