RANDOMKEY(3valkey)

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

πŸ’– RANDOMKEY β€” the Valkey command manual, but make it a group chat πŸ’–

okay so bestie, you know randomkey? it's a page in the Valkey Command Manual (that's the 3valkey section, mwah) and honestly? it's giving ✨main character✨. let's get into it.


✨ NAME ✨

randomkey β€” returns a random key name from the database. that's it. that's the whole vibe. no notes. πŸ’…


🌸 SYNOPSIS 🌸

RANDOMKEY

Return a random key from the currently selected database. yes queen, just the one. no args, no flags, no drama. πŸŽ€


πŸ¦‹ REPLY πŸ¦‹

so here's the tea β€” what you get back depends on which RESP you're speaking, and ngl the answer is basically the same either way, just with different spelling for "nothing". πŸ™ˆ

RESP2

One of the following, periodt:

  • valkey-protocol(7) Nil reply: when the database is empty. (empty database = no key for you, bestie 😭)
  • valkey-protocol(7) Bulk string reply: a random key in the database. πŸŽ‰

RESP3

One of the following, and yes it's the same deal but the "empty" one is named differently, don't @ me:


⚑ COMPLEXITY ⚑

O(1)

literally constant time. instant. iconic. it ate and left no crumbs. πŸ”₯


πŸ‘‘ ACL CATEGORIES πŸ‘‘

  • @keyspace
  • @read
  • @slow

three little tags and they're all slaying. πŸ’œ


🌈 HISTORY 🌈

  • Available since: 1.0.0 β€” she's been here since the very beginning, an OG fr fr. ⭐

🫢 SEE ALSO 🫢

the whole friend group, no cap:

copy(3valkey), del(3valkey), dump(3valkey), exists(3valkey), expire(3valkey), expireat(3valkey), expiretime(3valkey), keys(3valkey), migrate(3valkey), move(3valkey), object(3valkey), object-encoding(3valkey), object-freq(3valkey), object-help(3valkey), object-idletime(3valkey), object-refcount(3valkey), persist(3valkey), pexpire(3valkey), pexpireat(3valkey), pexpiretime(3valkey), pttl(3valkey), rename(3valkey), renamenx(3valkey), restore(3valkey), scan(3valkey), sort(3valkey), sort_ro(3valkey), touch(3valkey), ttl(3valkey), type(3valkey), unlink(3valkey), wait(3valkey), waitaof(3valkey)

go read them too, they're all baddies. πŸ’…


lowkey the whole thing is: RANDOMKEY = one random key, O(1), done. but you already knew that. iykyk. 😌

okay that's the whole page!! πŸŽ€ this was Valkey 9.0.0, dated 2025-10-21 β€” screenshot it, bookmark it, tell your friends. bye bestie, go grab a random key, mwah πŸ’–βœ¨πŸ¦‹

πŸ“¦ where this page comes from