PUBSUB-NUMSUB(3valkey)

πŸ“¦
version 9.0.6 Β· 2 versions
, in fedora 44

πŸ’– 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 from valkey-pubsub(7) PUBSUB in 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 πŸ’…


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