EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login
Home Software Development Software Development Tutorials Redis Tutorial Redis Master Slave
Secondary Sidebar
Redis Tutorial
  • Redis
    • Redis Pubsub
    • Redis GUI
    • Redis Database
    • Redis Get All Keys
    • Redis TTL
    • Redis EXPIRE
    • Redis Version
    • Redis EXPIRE
    • Redis List
    • Redis CLI Commands
    • Redis HSET
    • Redis FLUSHDB
    • Redis Key
    • Redis Persistence
    • Redis FLUSHALL
    • Redis pipeline
    • Redis SADD
    • Redis ZADD
    • Redis ZSET
    • Redis Get
    • Redis Replication
    • Redis Delete All Keys
    • Redis Use Cases
    • Redis HMSET
    • Redis Transactions
    • Redis Monitor
    • Redis HGET
    • Redis SETEX
    • Redis Rails
    • RedisJSON
    • Redis Get Key
    • Redis Auth
    • Redis gem
    • Redis Key Count
    • RedisTimeSeries
    • Redis Timeout
    • Redis LPUSH
    • Redis Architecture
    • Redis API
    • Redis Message Queue
    • Redis RPUSH
    • Redis Protocol
    • Redis Data Types
    • Redis Namespace
    • Redis ZRANGE
    • Redis Master Slave
    • Redis Memory Usage
    • Redis WATCH
    • Redis URL
    • Redis Key Value
    • Redis INCR
    • Redis EXISTS
    • Redis INFO
    • Redis HMGET
    • Redis Operator
    • Redis NOAUTH Authentication Required
    • Redis LRANGE
    • Redis RDB
    • Redis TLS
    • Redis HDEL
    • Redis WebSocket
    • Redis HGETALL
    • Redis GETSET
    • Node-RED WebSocket

Redis Master Slave

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.

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.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

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 [email protected]

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 [email protected]
requirepass [email protected]

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 [email protected]
requirepass [email protected]

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
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

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

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

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*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?

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more