SELECT(3valkey)
β¨ 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 β
(instant. no notes. iconic. π )
π ACL CATEGORIES π
@connection @fast
π HISTORY π
- Available since:
1.0.0
π SEE ALSO π
auth(3valkey)client(3valkey)client-caching(3valkey)client-capa(3valkey)client-getname(3valkey)client-getredir(3valkey)client-help(3valkey)client-id(3valkey)client-import-source(3valkey)client-info(3valkey)client-kill(3valkey)client-list(3valkey)client-no-evict(3valkey)client-no-touch(3valkey)client-pause(3valkey)client-reply(3valkey)client-setinfo(3valkey)client-setname(3valkey)client-tracking(3valkey)client-trackinginfo(3valkey)client-unblock(3valkey)client-unpause(3valkey)echo(3valkey)hello(3valkey)ping(3valkey)quit(3valkey)reset(3valkey)
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
- 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