# PUBLISH

> Send a message to every subscriber of a Pub/Sub channel.

URL: https://docs.hotkv.com/commands/publish/

```
PUBLISH channel message
```

- Group: Pub/Sub
- Complexity: O(N+M) where N is the channel's subscribers and M the subscribed patterns
- 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

| 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

```
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
```

## Compatibility

Same as Redis 7 and Valkey 8.

## See also

[SUBSCRIBE](https://docs.hotkv.com/commands/subscribe/index.md), [PSUBSCRIBE](https://docs.hotkv.com/commands/psubscribe/index.md),
[SPUBLISH](https://docs.hotkv.com/commands/spublish/index.md), [PUBSUB NUMSUB](https://docs.hotkv.com/commands/pubsub-numsub/index.md)