Skip to content

Ask the HotKV docs

Answers come only from these docs and can be wrong; check the linked pages before you rely on them.

PUBLISH

Last updated
PUBLISH channel message
Group
Pub/Sub
Complexity
O(N+M) where N is the channel's subscribers and M the subscribed patterns
Arity
3 (exactly, counting the command name)
Flags
pubsub, fast
HotKV Cloud
All plans
On-Premise
no license needed

PUBLISH delivers message to every connection subscribed to channel, and to every connection whose pattern subscriptions match it. Delivery is fire-and-forget: nothing is stored, and a subscriber that is not connected misses the message. In a cluster, the message is forwarded to the other nodes so their subscribers receive it as well.

When PUBLISH runs inside a transaction or a script, its message is delivered in order with the keyspace notifications of the commands before it.

Case RESP2 RESP3
Always Integer: the number of subscribers on this node that received the message Integer

In a cluster the count covers only the node that ran PUBLISH.

127.0.0.1:6379> PUBLISH news "release 2.0 is out"
(integer) 2
127.0.0.1:6379> PUBLISH nobody-listens "hello"
(integer) 0

Same as Redis 7 and Valkey 8.

SUBSCRIBE, PSUBSCRIBE, SPUBLISH, PUBSUB NUMSUB