SUBSCRIBE(3valkey)
π SUBSCRIBE (3valkey) π
okay bestie, welcome to the valkey command manual β this one's all about subscribe, and it's literally the glow-up your pub/sub era needed β¨
πΈ NAME πΈ
subscribe β the command that just sits there and listens. It's giving "I'm not texting first, I'm just waiting for messages to come to me" energy π§π
π SYNOPSIS π
SUBSCRIBE channel [channel...]
π¦ DESCRIPTION π¦
So basically, this command subscribes your client to the channels you name. You pass in one channel, or a whole lil squad of them, and now you're on the list. Subscribed. Locked in. π
Once your client enters the subscribed state, it is not supposed to issue any other commands. Like, at all. Not me being dramatic, that's just the rules π. The only exceptions are:
- more
SUBSCRIBE SSUBSCRIBE(seevalkey-ssubscribe(7))PSUBSCRIBE(seevalkey-psubscribe(7))UNSUBSCRIBE(seevalkey-unsubscribe(7))SUNSUBSCRIBE(seevalkey-sunsubscribe(7))PUNSUBSCRIBE(seevalkey-punsubscribe(7))PING(seevalkey-ping(7))RESET(seevalkey-reset(7))- and
QUIT(seevalkey-quit(7))
That's the whole guest list. Nothing else gets in while you're in subscribed state. periodt. π
BUT β and this is the plot twist β if you're using RESP3 (peep valkey-hello(7) HELLO), then a client can actually issue any commands while in subscribed state. Main character privilege, honestly π
Also good to know: you can call valkey-reset(7) RESET to exit the subscribed state. Escape hatch unlocked πͺβ¨
For the full lore, go read valkey-pubsub(7) Pub/sub. It's the extended universe π«Ά
π REPLY π
When it works, this command doesn't return anything in the normal sense. Instead, for each channel, one message gets pushed β and the first element of that message is the string subscribe. That's your confirmation that the command succeeded. It's like a little "delivered β
" receipt, one per channel.
π₯ COMPLEXITY π₯
O(N) β where N is the number of channels you're subscribing to. More channels, more work. Math is math π€·ββοΈ
π ACL CATEGORIES π
@pubsub@slow
β HISTORY β
- Available since:
2.0.0β an icon from the very beginning, no cap π
π 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)ssubscribe(3valkey)sunsubscribe(3valkey)unsubscribe(3valkey)
okay that's the whole page bestie, mwah π this was version 9.0.0, dated 2025-10-21 β go subscribe to something and slay πΈπ¦π
π¦ 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