spublish.3valkey - Man Page
Post a message to a shard channel
Synopsis
SPUBLISH
shardchannel message
Description
Posts a message to the given shard channel.
In Valkey Cluster, shard channels are assigned to slots by the same algorithm used to assign keys to slots. A shard message must be sent to a node that own the slot the shard channel is hashed to. The cluster makes sure that published shard messages are forwarded to all the node in the shard, so clients can subscribe to a shard channel by connecting to any one of the nodes in the shard.
For more information about sharded pubsub, see valkey-pubsub(7) Sharded Pubsub.
Reply
valkey-protocol(7) Integer reply: the number of clients that received the message. Note that in a Valkey Cluster, only clients that are connected to the same node as the publishing client are included in the count
Complexity
O(N) where N is the number of clients subscribed to the receiving shard channel.
Acl Categories
@fast @pubsub
History
- Available since: 7.0.0
Examples
For example the following command publish to channel orders
with a subscriber already waiting for message(s).
> spublish orders hello (integer) 1
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)