# SSUBSCRIBE

> Subscribe the connection to one or more shard channels.

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

```
SSUBSCRIBE shardchannel [shardchannel ...]
```

- Group: Pub/Sub
- Complexity: O(N) for N shard channels
- 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](https://docs.hotkv.com/commands/spublish/index.md), 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](https://docs.hotkv.com/commands/subscribe/index.md).

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

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

## Compatibility

Same as Redis 7 and Valkey 8.

## See also

[SUNSUBSCRIBE](https://docs.hotkv.com/commands/sunsubscribe/index.md), [SPUBLISH](https://docs.hotkv.com/commands/spublish/index.md),
[PUBSUB SHARDCHANNELS](https://docs.hotkv.com/commands/pubsub-shardchannels/index.md),
[SUBSCRIBE](https://docs.hotkv.com/commands/subscribe/index.md)

In a cluster: [Keys, slots and commands in a cluster](https://docs.hotkv.com/clustering/keys-and-commands/index.md#pubsub)