SUBSCRIBE to subscribe the current connection to one or more channels.
The server confirms each channel with its own reply carrying the running number of subscriptions this connection holds, and from then on messages published to those channels arrive on the connection as they are sent.
Under RESP2 a subscribed connection may only run subscription commands plus PING, RESET, and QUIT, which is why subscribers normally use a dedicated connection. Under RESP3 messages arrive as push replies and ordinary commands remain usable on the same connection. Messages published while the connection is not subscribed are not delivered later, since pub/sub keeps no history.
Syntax
Arguments
Important points
- This is a connection-oriented command and is available over native Redis TCP, not the stateless REST endpoint.
- Subscription commands require a dedicated TCP connection. In RESP3, subscription events use push replies.
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 TLSREDIS_URL from the Upstash console. REST examples use UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN.
Redis CLI
Redis CLI
ioredis
ioredis
node-redis
node-redis
redis-py
redis-py
go-redis
go-redis
jedis
jedis
redis-rs
redis-rs