SSUBSCRIBE(3valkey)
β¨ SSUBSCRIBE β¨
okay so bestie, we're in the Valkey Command Manual (that's the 3valkey manual, mwah) and today's main character is ssubscribe π
πΈ NAME πΈ
ssubscribe β she sits there and listens for messages published to shard channels. that's it, that's the job π§
π¦ SYNOPSIS π¦
SSUBSCRIBE shardchannel [shardchannel...]
π DESCRIPTION π
So basically, SSUBSCRIBE subscribes the client to the shard channels you name. iconic behavior, no notes π«Ά
Now here's the tea β In a Valkey cluster, shard channels get assigned to slots by the same algorithm used to assign keys to slots. Client(s) can subscribe to a node covering a slot β primary or replica β to receive the messages that get published. π
And here's the part you gotta remember, bestie: all the specified shard channels need to belong to a single slot to subscribe in a given SSUBSCRIBE call. but a client can subscribe to channels across different slots over separate SSUBSCRIBE calls. so like, one slot per call, k? π
For more info about sharded Pub/Sub, go peek at valkey-pubsub(7) Sharded Pub/Sub. iykyk π
π REPLY π
When it works, this command doesn't return anything. instead, for each shard channel, one message gets pushed as a confirmation that the command succeeded β and the first element of that message is the string ssubscribe. so cute π₯°
β οΈ heads up: this command can also return a -MOVED redirect. don't panic, it's just Valkey being like "girl, wrong node" π
π COMPLEXITY π
O(N) where N is the number of shard channels to subscribe to. linear, bestie, we love a predictable queen β¨
π§ ACL CATEGORIES π§
@pubsub@slow
β HISTORY β
- Available since: 7.0.0 β she's been serving since day one fr fr π
π EXAMPLES π
> ssubscribe orders
Reading messages... (press Ctrl-C to quit)
1) "ssubscribe"
2) "orders"
3) (integer) 1
1) "smessage"
2) "orders"
3) "hello"
look at her go π₯Ή you subscribe to orders, and then boom β an smessage shows up with hello in it. the way that just works. obsessed π₯
πΈ SEE ALSO πΈ
psubscribe(3valkey)publish(3valkey)pubsub(3valkey)pubsub-channels(3valkey)pubsub-help(3valkey)pubsub-numpat(3valkey)pubsub-numsub(3valkey)pubsub-shardchannels(3valkey)pubsub-shardnumsub(3valkey)punsubscribe(3valkey)spublish(3valkey)subscribe(3valkey)sunsubscribe(3valkey)unsubscribe(3valkey)
k bye bestie, go read the other pages, they're all slaying too π
this page is brought to you by Valkey 9.0.0, dated 2025-10-21, and the SSUBSCRIBE(3valkey) manual. periodt. π
π¦ where this page comes from
- fedora 44: valkey-doc 9.0.3-2.fc44 Β· CC-BY-SA-4.0
- fedora 44: valkey-doc 9.0.6-1.fc44 Β· CC-BY-SA-4.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms