SSUBSCRIBE
SSUBSCRIBE shardchannel [shardchannel ...]
- Group
- Pub/Sub
- Complexity
- O(N) for N shard channels
- Arity
- -2 (at least 2 words, counting the command name)
- Flags
- pubsub
- Keys
- first 1, last final argument, step 1
- HotKV Cloud
- All plans
- On-Premise
- no license needed
SSUBSCRIBE subscribes the connection to shard channels. A shard channel is
hashed to a cluster slot like a key, and its messages, sent with
SPUBLISH, stay within the shard (primary and replicas)
that serves that slot instead of going to every node. This keeps Pub/Sub
traffic from growing with the size of the cluster. Outside cluster mode, shard
channels behave like separate ordinary channels.
In a cluster, all channels in one call must hash to the same slot, and the
command is redirected with MOVED to the node that serves it. If the slot
moves to another shard later, the subscribers are unsubscribed (they receive
an sunsubscribe message) and should subscribe again on the new owner.
The connection enters subscribed mode, as with SUBSCRIBE.
Return value
Section titled “Return value”For each shard channel, a confirmation:
| Element | Value |
|---|---|
| 1 | Bulk string ssubscribe |
| 2 | Bulk string: the shard channel |
| 3 | Integer: the number of shard channels this connection is now subscribed to |
Each message then arrives as smessage, the shard channel, and the payload. On
RESP3 these are push messages.
Examples
Section titled “Examples”127.0.0.1:6379> SSUBSCRIBE orders:{eu}1) "ssubscribe"2) "orders:{eu}"3) (integer) 11) "smessage"2) "orders:{eu}"3) "order 1001 placed"Compatibility
Section titled “Compatibility”Same as Redis 7 and Valkey 8.
See also
Section titled “See also”SUNSUBSCRIBE, SPUBLISH, PUBSUB SHARDCHANNELS, SUBSCRIBE
In a cluster: Keys, slots and commands in a cluster
Was this page helpful?
Thanks for the feedback.