This tool copies all keys from a Redis cluster to another one as able as possible by command.
I want to migrate my redis cluster from 3 to 5.
Official Redis client has migration feature but source data is deleted.
There is an alternative way to import data from external instances to a Redis Cluster, which is to use the
redis-cli --cluster import
command. The command moves all the keys of a running instance (deleting the keys from the source instance) to the specified pre-existing Redis Cluster.
I need a copy tool.
- CLUSTER SLOTS
- For mapping nodes and slots
- CLUSTER COUNTKEYSINSLOT
- For counting keys in a slot
- CLUSTER GETKEYSINSLOT
- For listing keys in a slot
- DUMP
- For fetching a key from source node
- PTTL
- For fetching remained TTL milliseconds of a key
- RESTORE
- For transferring a key to destination node
- AUTH
- SSL
- RESP3
- Windows
so on and so forth
- Use non-blocking IO
$ git clone https://github.com/supercaracal/redis-cluster-data-transfer.git
$ cd redis-cluster-data-transfer/
$ make
$ docker compose up -d
$ bin/cli 127.0.0.1:16371
>> set key1 1
OK
>> set key2 2
OK
>> set key3 3
OK
>> quit
$ bin/exe 127.0.0.1:16371 127.0.0.1:16381
3 keys were found
3 keys were copied
0 keys were skipped
0 keys were failed
$ bin/diff 127.0.0.1:16371 127.0.0.1:16381
3 keys were found
3 keys were same
0 keys were different
0 keys were deficient
0 keys were failed
0 keys were skipped
$ bin/cli 127.0.0.1:16381
>> get key1
1
>> get key2
2
>> get key3
3
>> quit
$
$ bin/exe 127.0.0.1:16371 127.0.0.1:16381 -C
It takes approximately 3 minutes while 10 million keys are copied. This program is I/O bound.