SUBSCRIBE(3valkey)

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

πŸ’– 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 (see valkey-ssubscribe(7))
  • PSUBSCRIBE (see valkey-psubscribe(7))
  • UNSUBSCRIBE (see valkey-unsubscribe(7))
  • SUNSUBSCRIBE (see valkey-sunsubscribe(7))
  • PUNSUBSCRIBE (see valkey-punsubscribe(7))
  • PING (see valkey-ping(7))
  • RESET (see valkey-reset(7))
  • and QUIT (see valkey-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 πŸ‘‘


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