SELECT
SELECT index
- Group
- Connection
- Complexity
- O(1)
- Arity
- 2 (exactly, counting the command name)
- Flags
- fast, loading
- HotKV Cloud
- All plans
- On-Premise
- no license needed
SELECT changes the logical database the current connection reads and
writes. Databases are numbered from 0, and how many there are is set by the
databases setting (16 by default, changed only with a restart). A new
connection starts in database 0. Other connections are not affected.
Return value
Section titled “Return value”| Case | Reply (RESP2 and RESP3) |
|---|---|
| Switched | Simple string OK |
index is not an integer |
Error ERR value is not an integer or out of range |
index does not fit a 32-bit integer |
Error ERR value is out of range, value must between -2147483648 and 2147483647 |
index is negative, or not below databases |
Error ERR DB index is out of range |
A non-zero index on a cluster node with the default cluster-databases 1 |
Error ERR SELECT is not allowed in cluster mode |
An index not below cluster-databases on a cluster node with more databases |
Error ERR DB index is out of range |
Examples
Section titled “Examples”127.0.0.1:6379> SET k "in db 0"OK127.0.0.1:6379> SELECT 3OK127.0.0.1:6379[3]> GET k(nil)127.0.0.1:6379[3]> SELECT 16(error) ERR DB index is out of rangeCompatibility
Section titled “Compatibility”Same replies as Redis 7. As in Redis Cluster, a cluster node has one database by
default and SELECT 0 is accepted there. As in Valkey 9, the setting
cluster-databases (1 to 128, set at startup) gives a cluster node more
databases, and SELECT then works up to that number. See
Databases in a cluster.
See also
Section titled “See also”Was this page helpful?
Thanks for the feedback.