SPUBLISH(3valkey)
π 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 π
psubscribe(3valkey)publish(3valkey)pubsub(3valkey)pubsub-channels(3valkey)pubsub-help(3valkey)pubsub-numpat(3valkey)pubsub-numsub(3valkey)pubsub-shardchannels(3valkey)pubsub-shardnumsub(3valkey)punsubscribe(3valkey)ssubscribe(3valkey)subscribe(3valkey)sunsubscribe(3valkey)unsubscribe(3valkey)
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
- 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