Skip to content

Ask the HotKV docs

Answers come only from these docs and can be wrong; check the linked pages before you rely on them.

SSUBSCRIBE

Last updated
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.

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.

127.0.0.1:6379> SSUBSCRIBE orders:{eu}
1) "ssubscribe"
2) "orders:{eu}"
3) (integer) 1
1) "smessage"
2) "orders:{eu}"
3) "order 1001 placed"

Same as Redis 7 and Valkey 8.

SUNSUBSCRIBE, SPUBLISH, PUBSUB SHARDCHANNELS, SUBSCRIBE

In a cluster: Keys, slots and commands in a cluster