SPUBLISH(3valkey)

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

πŸ’Œ SPUBLISH β€” the valkey command manual, but make it cute

okay bestie, so this is SPUBLISH from the Valkey Command Manual, and honestly? it's giving main character energy for sharded pubsub. let's get into it 🫢


✨ NAME ✨

spublish β€” post a message to a shard channel. that's it, that's the vibe. πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

SPUBLISH shardchannel message

🌸 DESCRIPTION 🌸

so what it does is: it posts a message to the given shard channel. periodt. πŸ’–

now here's the part where you gotta lock in πŸ”₯ β€” in Valkey Cluster, shard channels get assigned to slots using the exact same algorithm that assigns keys to slots. no cap.

and that means a shard message must be sent to a node that owns the slot the shard channel is hashed to. like, that's non-negotiable bestie, that's just how the hashing works 😭

the good news though? the cluster makes sure that published shard messages get forwarded to all the nodes in the shard. so your clients can subscribe to a shard channel by connecting to any one of the nodes in the shard. iconic behaviour, honestly ✨

for more info about sharded pubsub, go peek at valkey-pubsub(7) β†’ Sharded Pubsub. 🌈


πŸ’¬ REPLY πŸ’¬

valkey-protocol(7) Integer reply: the number of clients that received the message. πŸ‘‘

⚠️ but heads up bestie: in a Valkey Cluster, only clients that are connected to the same node as the publishing client get included in the count. so don't come for that number thinking it's the whole cluster, it is NOT πŸ’€

πŸ¦‹ COMPLEXITY πŸ¦‹

O(N) where N is the number of clients subscribed to the receiving shard channel. straightforward, slay. 🧚


πŸ’… ACL CATEGORIES πŸ’…

  • @fast
  • @pubsub

πŸ“œ HISTORY πŸ“œ

  • Available since: 7.0.0 ⭐

πŸ“ EXAMPLES πŸ“

so like, say the following command publishes to channel orders with a subscriber already waiting for message(s). look how cute this is:

> spublish orders hello
(integer) 1

one client caught it. we love to see it. πŸ™ˆ


πŸ‘€ SEE ALSO πŸ‘€


okay that's the whole page, bestie, you ate it πŸ’– this was Valkey 9.0.0, dated 2025-10-21, and the page is literally called SPUBLISH(3valkey). go forth and publish those shard messages, queen πŸ‘‘βœ¨

πŸ“¦ where this page comes from