Get the App
SLTechnology News&Howtos  ›  Database  › 

What is the meaning of master-slave replication in Redis

Shulou Source: shulou.com Published: 2022-05-31 18:55:45 09月20日 Update

This article introduces the relevant knowledge of "what is the meaning of master-slave replication in Redis". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Master-slave replication:

1. Master can have multiple slave.

2. Multiple slave can connect not only to the same master, but also to other slave.

3. Master-slave replication will not block master, and master can continue to process client requests when synchronizing data.

4. Improve the scalability of the system.

Master-slave replication process:

1. Slave establishes a connection with master and sends sync synchronization commands.

2. Master will start a background process to save the database snapshot to a file, while the master main process will start collecting new write commands and caching them.

3. After the background has finished saving, send this file to slave.

4. Slave saves the secondary file to the hard disk.

Configure the master and slave servers:

You only need to add the following configuration to the configuration file of slave:

[root@D2-TRAIN15 redis-4.0.1] # egrep "slaveof | masterauth" redis.conf

# Master-Slave replication. Use slaveof to make a Redis instance a copy of

Slaveof # specifies the IP and port of the master.

Masterauth # specifies the password for master.

Modify the configuration file of the slave server:

[root@D2-TRAIN15 redis-4.0.1] # egrep "slaveof | masterauth" redis.conf

# Master-Slave replication. Use slaveof to make a Redis instance a copy of

Slaveof 10.163.89.245 6379

Masterauth 123456

[root@D2-TRAIN15 redis-4.0.1] # src/redis-server redis.conf

[root@D2-TRAIN15 redis-4.0.1] # src/redis-cli

127.0.0.1 purl 6379 > info replication

# Replication

Role:slave

Master_host:10.163.89.245

Master_port:6379

Master_link_status:up

Master_last_io_seconds_ago:1

View the main library:

127.0.0.1 purl 6379 > info replication

# Replication

Role:master

Connected_slaves:1

Slave0:ip=10.163.89.15,port=6379,state=online,offset=154,lag=1

Test:

Main library:

127.0.0.1 purl 6379 > set name master

OK

From the library:

127.0.0.1 purl 6379 > get name

"master"

This is the end of the content of "what is the meaning of master-slave replication in Redis"? thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Master and slave file configuration meaning content background command multiple data more server knowledge process process synchronization service utility learning and then scalability. Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Shulou Technology MySQL Linux Redmi