Skip to content

Ask the HotKV docs

Answers come only from these docs and can be wrong; check the linked pages before you rely on them.

SELECT

Last updated
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.

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
127.0.0.1:6379> SET k "in db 0"
OK
127.0.0.1:6379> SELECT 3
OK
127.0.0.1:6379[3]> GET k
(nil)
127.0.0.1:6379[3]> SELECT 16
(error) ERR DB index is out of range

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.

SWAPDB, MOVE, DBSIZE, FLUSHDB, RESET