Skip to main content
Use PUBLISH to send a message to a channel. The reply is the number of subscribers the message was delivered to, counting both channel and pattern subscribers, so a reply of 0 means nobody was listening. Delivery is fire and forget: messages are not stored and a client that is not connected at that moment never sees them, so use streams when messages must survive a disconnect or be replayed. Publishing works over both the REST API and a TCP connection, while subscribing requires a TCP connection.

Syntax

Arguments

Response

The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below.
Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply.

Examples

TCP examples use the TLS REDIS_URL from the Upstash console. REST examples use UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN.