Migrate from redis server to a new one

mo2men_1

Mo'men Ahmed

Posted on September 19, 2021

Migrate from redis server to a new one

If you have some data stored on a redis server, and for any reason, you need to migrate the data to another redis server, then you may use MIGRATE command in a redis-cli terminal.

The MIGRATE command

MIGRATE destination-host destination-port "" destination-db-index timeout [COPY] [REPLACE] [AUTH password] [AUTH2 username password] [KEYS key [key ...]]

Options:

  • COPY -- Do not remove the key from the local(source) instance.
  • REPLACE -- Replace existing key on the remote(destination) instance.
  • KEYS -- If the key argument is an empty string, the command will instead migrate all the keys that follow the KEYS option (see the above section for more info).

For more info check MIGRATE redis docs here.

Example

Suppose you want to migrate data from source-host to destination-host, you should open redis-cli by writing redis-cli in a terminal in the source redis server machine, then run the following command replacing the host and port with the right values:
MIGRATE destination-host destination-port "" 0 5000 COPY KEYS key1 key2

💖 💪 🙅 🚩
mo2men_1
Mo'men Ahmed

Posted on September 19, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related