PUBLISH
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.
Return value
Section titled “Return value”| 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.
Examples
Section titled “Examples”127.0.0.1:6379> PUBLISH news "release 2.0 is out"(integer) 2127.0.0.1:6379> PUBLISH nobody-listens "hello"(integer) 0Compatibility
Section titled “Compatibility”Same as Redis 7 and Valkey 8.
See also
Section titled “See also”Was this page helpful?
Thanks for the feedback.