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.
- 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.
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.
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:
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.
# apt install redis-server
2. While installing the redis, now we are starting the server by using the following command.
3. While starting the server now in this step we are checking the status and installation on both servers as follows.
4. Now in this step we are doing the below changes in the master server into the configuration file as follows.
# vi /etc/redis/redis.conf bind 127.0.0.1 ::1 192.168.92.1 protected-mode no requirepass Test@123
5. Now in this step we are doing the below changes in the first slave server into the configuration file as follows.
# 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
6. Now in this step we are doing the below changes in the second slave server into the configuration file as follows.
# 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
7. After adding the changes in the configuration file now we are taking restart of all the servers as follows.
8. After restarting all the servers now we are checking the status of replication.
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.
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.
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 –