SSUBSCRIBE(3valkey)

πŸ“¦
version 9.0.6 Β· 2 versions
, in fedora 44

✨ 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 🌸


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