PUBSUB-SHARDNUMSUB(3valkey)

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

πŸ’– PUBSUB-SHARDNUMSUB πŸ’–

okay bestie, welcome to the Valkey Command Manual entry for pubsub-shardnumsub β€” yes it's a mouthful, no you're not gonna say it out loud, just trust me 🫢


✨ NAME ✨

pubsub-shardnumsub β€” literally just returns the count of subscribers of shard channels. that's the whole job. she's got one task and she ate πŸ’…


🌸 SYNOPSIS 🌸

PUBSUB SHARDNUMSUB shardchannel [shardchannel...]

πŸ¦‹ DESCRIPTION πŸ¦‹

So here's the tea: this one gives you back the number of subscribers for the shard channels you name. one channel, five channels, whatever β€” you ask, it counts. ✨

And lowkey the most important thing: it is totally valid to call this command with no channels at all. no channels? no problem. it'll just return an empty list. iconic behaviour honestly.

Cluster note (read this one fr fr): in a Valkey Cluster, the replies from valkey-pubsub(7) PUBSUB in a cluster only report information from the node's own Pub/Sub context β€” not the entire cluster. so don't come for the numbers like they're the whole picture, bestie, they're not. πŸ™ˆ

πŸ’œ REPLY πŸ’œ

valkey-protocol(7) Array reply: the number of subscribers per shard channel. and here's the pattern you gotta memorise:

  • every even element (including the 0th) is the channel name πŸ’–
  • every odd element is the number of subscribers πŸ’–

so it's name, count, name, count, name, count... you get it. it's giving choreography. πŸŽ€


πŸ”₯ COMPLEXITY πŸ”₯

O(N) for the SHARDNUMSUB subcommand, where N is the number of requested shard channels. yes queen, linear, slay. ⭐


πŸ‘‘ ACL CATEGORIES πŸ‘‘

  • @pubsub
  • @slow

(iykyk which keys you need πŸ”‘)


🌈 HISTORY 🌈

  • Available since: 7.0.0 β€” she's not new new, but she's not ancient either. a respectable era. πŸ’«

πŸ“ EXAMPLES πŸ“

okay watch this, one channel called orders, and:

> PUBSUB SHARDNUMSUB orders
1) "orders"
2) (integer) 1

so "orders" is element zero (the channel name, as promised) and (integer) 1 is the subscriber count. one whole subscriber out here holding it down. periodt. πŸ’…


🧚 SEE ALSO 🧚


and that's the whole page, bestie!! 🫢 this one's from version 9.0.0, dated 2025-10-21, and it's the PUBSUB-SHARDNUMSUB(3valkey) entry in the Valkey Command Manual. go forth and count your subscribers. mwah πŸ˜­πŸ’–

πŸ“¦ where this page comes from