SELECT(3valkey)

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

✨ SELECT πŸ’…

okay so bestie, welcome to SELECT(3valkey) β€” straight out of the Valkey Command Manual, and yes we're gonna make database switching feel like picking a new outfit πŸŽ€


🌸 SYNOPSIS 🌸

SELECT index

πŸ’– DESCRIPTION πŸ’–

So basically? SELECT picks which Valkey logical database you're hanging out in, using the zero-based numeric index you give it. Baby's first connection always starts in database 0 β€” no exceptions, that's just where everybody spawns. 🌱

By default Valkey hands you 16 logical databases, indexed from 0 to 15. Want more? You can bump that number by setting the databases parameter in the configuration file. But listen β€” that change has to happen at startup and it cannot be modified at runtime. So decide before you launch, bestie, no take-backs. 🫢

Selectable Valkey databases are basically a form of namespacing: all the databases still get persisted in the same RDB / AOF file. The glow-up is that different databases can totally have keys with the same name, and commands like valkey-flushdb(7) FLUSHDB, valkey-swapdb(7) SWAPDB or valkey-randomkey(7) RANDOMKEY work on specific databases. Periodt. πŸ‘‘

In practical terms β€” and this is the real talk β€” Valkey databases should be used to separate different keys belonging to the same application (if needed), and not to cram multiple unrelated applications into a single Valkey instance. Don't do that. It's giving chaos. 😭

Valkey 9.0 and later supports multiple databases in cluster mode. You can use SELECT <dbid> to switch between them. slay ✨

Since the currently selected database is a property of the connection, clients should track the currently selected database and re-select it on reconnection. Like, if your connection dips and comes back, it doesn't remember your vibe β€” you gotta remind it. πŸ’€

And while there's no dedicated command to query the currently selected database for a connection, you can infer it from the output of valkey-client-list(7) CLIENT LIST or valkey-client-info(7) CLIENT INFO, where each client entry includes the db=N field indicating the selected database. iykyk πŸ”


πŸ¦‹ REPLY πŸ¦‹

valkey-protocol(7) Simple string reply: OK.


⭐ COMPLEXITY ⭐

O(1)

(instant. no notes. iconic. πŸ’…)


πŸŽ€ ACL CATEGORIES πŸŽ€

@connection @fast


🌈 HISTORY 🌈

  • Available since: 1.0.0

πŸ‘‘ SEE ALSO πŸ‘‘


version 9.0.0, dated 2025-10-21, and yeah this whole page is literally SELECT(3valkey). go switch databases responsibly bestie, mwah πŸ’œπŸ§š

πŸ“¦ where this page comes from