EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home Software Development Software Development Tutorials Redis Tutorial Redis Master Slave
 

Redis Master Slave

Updated February 17, 2023

Introduction to Redis Master Slave

Redis master slave uses the asynchronous method for transferring the data from master to slave. The slave will acknowledge the received data sent by the master node and the master node will contain multiple slaves. Redis supports the cascading type of replication, so our slave connects to another slave. It is very good practice to enable the persistence options for the node of a master slave.

 

 

Redis Master Slave.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

Key Takeaways

  • At the time of creating master slave multiple replications, we know that several redis servers will need to deploy.
  • In the same way, we are spreading multiple data centers. In case the master is not reachable then the slave of the server takes place of the master server.

What is Redis Master Slave?

In master, the slave client is reading and writing the master and it will only read the data from the slave. It will generally be in a pairs and the master will replicate data to the slave. It is an important technique to ensure the performance and availability of the data. The architecture is known computing paradigm which contains one device to process and control the multiple subordinate or processes.

Master slave architecture is used in many of applications for databases or networking. Master slave replication is a method used to replicate databases to improve performance and redundancy. The system contains the master database, which acts as an interface to the outside world and was used to handle the read and write requests. At the time change is made in the other master database the same change will be propagated to the slave database which was connected to the master.

Redis Master Slave Multiple Replications

Redis allows the high availability of data served with minimal intervention. Redis is simple there are multiple types of tools to manage the master slave’s multiple replications. In the below figure, we can see that we have only one master and we have created three slaves. The single master will replicate the data across three slaves at the same time. When any write operation is done on the master server same time it will be replicated on all the slave servers. The master slave multiple replications will define the below features as follows.

  • Performance – By creating the master and slave server we can improve the performance of our application. We can divide the read and write load into multiple slave servers.
  • Backup creation – Backup creation is very simple. We can create a backup on the slave server without disrupting any transaction on the master server.
  • Running analytics and BI query – We are running BI and analytics query on the slave server, without disrupting the master server.

Below is the sample diagram of master slave replication which contains a single master and multiple slave servers.

Redis Master Slave Diagram

Basically, the master slave is a method used to replicate the database from one server to another server.

The below example shows that master slave multiple replications by using multiple masters as follows. In the below example we can see that it will contain two master and two slave servers.

2 Redis Master Slave Servers

In the above figure, we can see that we have defined two masters and two slaves while reading data, the client connects to the slave and master, but while writing data client connects to the master server only.

Redis Master Slave Architecture

Basically, it is based on the master slave architecture. Redis server is running by using the following two modes as follows.

  • Master mode
  • Slave mode

We can configure which mode is for reading and which is for writing. Redis has recommended executing the write query on the master and read query on the slave server. In redis one master is replicating data on one or multiple slave servers. In redis master slave replication is done async way.

Below figure shows redis master slave architecture as follows:

Redis Master Slave Architecture

In the below diagram, we have two choices while creating the new master replication, either we add a new machine to the redis master or make the existing redis slave a master server. While choosing the second approach existing slave contains all the data, after connecting to the new slave as a master all the data again replicates to the old master.

All the redis slave contains the latest data which was changed on the master server. If any slave server goes down then another slave server read the request which comes from the client. As we know that redis is an in-memory data structure used to implement non-relational databases of key value.

The replication architecture is non-blocking, we can say that master will operate at the time the slave database will sync the data. Also, the slave database handles the read query request which comes from the client.

How to Setup Redis Master Slave Installing?

To setup master slave replication, we need to follow below steps as follows:

In the below example, we define one master and two slave servers as follows.

1. In the first step we are installing the redis on both the master and slave databases. We are installing the same by using the apt command.

Command:

# apt install redis-server

Output:

Redis Master Slave - Apt Command

2. While installing the redis, now we are starting the server by using the following command.

Command:

# redis-server

Output:

starting the server

3. While starting the server now in this step we are checking the status and installation on both servers as follows.

Command:

# redis-cli

Output:

Status and Installation

4. Now in this step we are doing the below changes in the master server into the configuration file as follows.

Command:

# vi /etc/redis/redis.conf
bind 127.0.0.1 ::1 192.168.92.1
protected-mode no
requirepass Test@123

Output:

Configuration file

5. Now in this step we are doing the below changes in the first slave server into the configuration file as follows.

Command:

# vi /etc/redis/redis.conf
bind 127.0.0.1 ::1 192.168.92.2
protected-mode no
replicaof 192.168.92.1 6379
masterauth Test@123
requirepass Test@123

Output:

First Slave Server

6. Now in this step we are doing the below changes in the second slave server into the configuration file as follows.

Command:

# vi /etc/redis/redis.conf
bind 127.0.0.1 ::1 192.168.92.3
protected-mode no
replicaof 192.168.92.1 6379
masterauth Test@123
requirepass Test@123

Output:

second slave server

7. After adding the changes in the configuration file now we are taking restart of all the servers as follows.

Command:

# redis-server

Output:

Redis Master Slave - Configuration File

8. After restarting all the servers now we are checking the status of replication.

Command:

info replication

Output:

checking the status of replication

Conclusion

Master slave architecture is used in many of applications for databases or networking. It uses the asynchronous method for transferring the data from master to slave. The slave will acknowledge the received data which was sent by the master node and the master node will contain multiple slaves.

FAQ

Given below are the FAQs mentioned:

Q1. What is the use of master slave replication in redis?

Answer: Master slave replication is used to divide the load between master and slave. Master is used to process the write query and slave is used to process the read query.

Q2. Which mode is used to set up master slave replication in redis?

Answer: Redis uses two modes to set up master slave replication in redis i.e. slave mode and master mode.

Q3. How can we test the replication in redis?

Answer: We are testing the redis replication by executing info replication command. It will show all information related to replication.

Recommended Articles

This is a guide to Redis Master Slave. Here we discuss the introduction, redis master slave multiple replications, architecture, and setup installing. You may also have a look at the following articles to learn more –

  1. Redis Get All Keys
  2. Redis GUI
  3. Redis Pubsub
  4. Redis Version

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW