PUBSUB-NUMSUB(3valkey)
π PUBSUB-NUMSUB π
okay bestie, so this is a Valkey command manual page β PUBSUB-NUMSUB from the 3valkey section. yes the section number is part of the name, we don't make the rules. let's get into it π«Ά
β¨ NAME β¨
pubsub-numsub β literally just: it returns a count of subscribers to channels. that's the whole job. iconic. π
π SYNOPSIS π
PUBSUB NUMSUB channel [channel...]
like, you give it channels, it counts. one channel minimum, but you can pile on more, no cap. β¨
πΈ DESCRIPTION πΈ
so here's the tea π: this gives you the number of subscribers for each channel you asked about β and super important detail, that count is exclusive of clients subscribed to patterns. so the pattern girlies (PSUBSCRIBE energy) are not in this number. if you want those, that's a whole different command, iykyk.
also, plot twist: it is valid to call this command without channels. yes, for real. if you do that, it will just return an empty list. no channels, no drama, empty list, moving on. π
Cluster note, listen up: 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. but β and this is the part everyone forgets β the replies fromvalkey-pubsub(7)PUBSUBin a cluster only report information from the node's Pub/Sub context, rather than the entire cluster. so you're getting that node's view, not the whole cluster's. don't @ me, that's just how it is. π
β REPLY β
valkey-protocol(7) Array reply: the number of subscribers per channel. and the way it's laid out? each even element (including the 0th) is the channel name, and each odd element is the number of subscribers. so it's name, count, name, count, name, count β alternating, cute little pattern, slay. π
π₯ COMPLEXITY π₯
O(N) for the NUMSUB subcommand, where N is the number of requested channels. so more channels = more work. math is math. β¨
π ACL CATEGORIES π
@pubsub @slow
π HISTORY π
- Available since:
2.8.0β a classic, been here since forever, lowkey a legend. π
π SEE ALSO π
psubscribe(3valkey)publish(3valkey)pubsub(3valkey)pubsub-channels(3valkey)pubsub-help(3valkey)pubsub-numpat(3valkey)pubsub-shardchannels(3valkey)pubsub-shardnumsub(3valkey)punsubscribe(3valkey)spublish(3valkey)ssubscribe(3valkey)subscribe(3valkey)sunsubscribe(3valkey)unsubscribe(3valkey)
and that's the whole page, bestie π«Ά go count some subscribers, you're gonna eat. πβ¨
mwah π β this lil manual moment brought to you by Valkey 9.0.0, dated 2025-10-21. periodt. π
π¦ where this page comes from
- fedora 44: valkey-doc 9.0.3-2.fc44 Β· CC-BY-SA-4.0
- fedora 44: valkey-doc 9.0.6-1.fc44 Β· CC-BY-SA-4.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms