Migrate redis server data from one instance to another instance

redis data migration

This blog will be helpful for people who looking for migrate redis server from one service to another like from AWS to GoogleCloud, DigitalOcean to AWS etc. Or just move redis data from one instance to another instance or live sync their redis data in another slave machine.

We are going to use master/slave approach to achieve this. Following steps are need to complete this.

1. Open redis ports

Please make sure to open redis port (default port is 6379) in both slave and master for data transfer between them. If you are using AWS, please update inbound rules in security group associated with redis instance.
Note: Port need to be opened in both master and slave to make it work.

2. Update auth details

If you are using password authentication in master, please update let slave know what is the password used for authentication by update redis configuration file(redis.conf).

#> masterauth <password-used-in-master>

If you are not using password in master, then please set this for secure communication. You can do this by set your password in master configuration file(redis.conf) as mentioned below.

#> requirepass <your-secure-password>

Note: After update configuration we need to restart redis server to apply last changes.

3. Start replication

There are two way to start replication.

3.1 First way is to run following commands from slave machine to start data replication. Login to redis-cli console using redis host, port and password.
=> redis-cli -h <domain-or-public-ip-of-redis-server-instace> -p 6379
=> auth <password>

Once entered into redis-cli console, please run following.
Syntax : => slaveof <master-ip> <master-port>
Sample : => slaveof 172.234.234.23 6379

3.2 Second way is to update configuration file(redis.conf) in redis to start replication. Please update following property and restart to start replication.
=> replicaof <public-ip-of-master> port

4. Verify replication

That’s all, replication should have started now. You can check it by run keys command in redis to check keys replicated from master. Also you can run info command to check replication detail.

=> keys *
OR
=> info replication

Stop replication

Migration will be completed within few seconds/minutes. If you are ready to use slave as a master. Please do the following from slave instance. If you used slaveof command to start replication then run following command
=> slaveof no one
If you used replicaof property in configuration to start replication then remove this property from configuration file and restart the redis server.

That’s all. New instance is ready to use in live application as master.

--

--

--

Ruby on Rails developer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

JavaScript: The Weird Parts (Part I: Data Types, Type Coercion, PBR)

A 3D DP problem

5 ways to iterate an array in javascript

IMPT LINKS

How to build an Angular 13 and above project in development mode?

How to build a Vue.js application using DevExtreme UI components and a .Net Core API

BASIC INTRODUCTION TO REACT

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Premanandh

Premanandh

Ruby on Rails developer

More from Medium

Reducing Visibility Timeout — Exception Scenarios- Hack I did

Handle multiple databases in bitbucket Pipelines

Aws lambda and API gateway with Execution logs

OAuth 2.0 Custom Application Enablement