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.

SWAPDB

Last updated
SWAPDB index1 index2
Group
Server
Complexity
O(1)
Arity
3 (exactly, counting the command name)
Flags
write, fast
HotKV Cloud
All plans
On-Premise
no license needed

SWAPDB exchanges the data of two databases. Connections using either database see the other one’s data at once, without reconnecting. The swap is atomic: no client sees a half-swapped state.

A typical use is to rebuild a data set in a spare database, then swap it in for the live one. Transactions that WATCH keys in either database fail at EXEC, since the watched data may have changed.

Case Reply (RESP2 and RESP3)
Swapped (or both indexes are the same) Simple string OK
First index not a 32-bit integer Error ERR invalid first DB index
Second index not a 32-bit integer Error ERR invalid second DB index
An index is negative or not below databases Error ERR DB index is out of range
Cluster mode, whatever cluster-databases is Error ERR SWAPDB is not allowed in cluster mode
127.0.0.1:6379> SELECT 1
OK
127.0.0.1:6379[1]> SET catalog:version "v2"
OK
127.0.0.1:6379[1]> SWAPDB 0 1
OK
127.0.0.1:6379[1]> SELECT 0
OK
127.0.0.1:6379> GET catalog:version
"v2"

Same replies as Redis 7 and Valkey 8.

SELECT, MOVE, FLUSHDB

In a cluster: Keys, slots and commands in a cluster