


Let's talk about the master-slave replication architecture in Redis6 and see what its characteristics are!
This article will take you to understand the master-slave replication architecture in Redis6, and introduce the characteristics of Redis6 master-slave replication. I hope it will be helpful to everyone!
Introduction to master-slave replication
Master-slave replication refers to copying data from one Redis server to another Redis server. The former is the master node, and the latter becomes the slave node; data replication is one-way, and can only be from the master node to the slave node. By default, each Redis server is a master node, and a master node can have multiple slave nodes (or no slave nodes), but a slave node can only have one master node. [Related recommendations: Redis Video Tutorial]
The benefits of using master-slave replication: reading and writing are separated, which can expand the reading capacity of the master node and share the pressure on the master node. For disaster recovery, once the master node goes down, the slave node can be used as the backup of the master node and can be installed at any time.
Architecture Introduction
The slave node copies the data of the master node. After copying, we can do a read-write separation. If it is a single node, application requests are concentrated on the master node, but with the slave node, it can bear part of the read pressure. The master node can perform read and write operations, while the slave node can only perform read operations. This will share the pressure on the master node.
Redis master-slave replication, one master and two slaves architecture environment preparation
After talking about so many concepts, let’s start deploying the master-slave of Redis Let’s copy the architecture. This time we deploy a one-master-two-slave architecture.
#创建文件 mkdir -p /data/redis/master/data mkdir -p /data/redis/slave1/data mkdir -p /data/redis/slave2/data #从节点开启只读模式(默认) replica-read-only yes #从节点访问主节点的密码,和requirepass⼀样 masterauth 123456 #哪个主节点进⾏复制 replicaof 8.129.113.233 6379
First create a master node, touch a redis.conf file in the data/redis/master/data directory, edit the redis.conf file
bind 0.0.0.0 port 6379 daemonize yes requirepass "123456" logfile "/usr/local/redis/log/redis1.log" dbfilename "xdclass1.rdb" dir "/usr/local/redis/data" appendonly yes appendfilename "appendonly1.aof" masterauth "123456"
Then create slave node 1, in data Build redis.conf
bind 0.0.0.0 port 6380 daemonize yes requirepass "123456" logfile "/usr/local/redis/log/redis2.log" dbfilename "xdclass2.rdb" dir "/usr/local/redis/data" appendonly yes appendfilename "appendonly2.aof" replicaof 8.129.113.233 6379 masterauth "123456"
in the /redis/slave1/data directory. Create slave node 2 and build redis.conf
bind 0.0.0.0 port 6381 daemonize yes requirepass "123456" logfile "/usr/local/redis/log/redis3.log" dbfilename "xdclass3.rdb" dir "/usr/local/redis/data" appendonly yes appendfilename "appendonly3.aof" replicaof 8.129.113.233 6379 masterauth "123456"
in the data/redis/slave2/data directory. Note: Remember to turn off the firewall. , Alibaba Cloud Server remembers to open the network security group.
After creation, start the configured node
Startup method:
#启动主 ./redis-server/data/redis/master/data/redis.conf #启动从1 ./redis-server/data/redis/slave1/data/redis.conf #启动从2 ./redis-server/data/redis/slave2/data/redis.conf
Use info replication to view the status of the current node
Master-slave Replication and read-write verification
1.在主节点创建一个key set name jack 2.在两个从节点测试是否能拿到主节点的数据 get name 3.在从节点set key是失败的,因为从节点只支持读操作
Redis6 master-slave architecture-analysis of replication read-write separation principle
Master-slave replication is divided into two types: one One is to perform full synchronization when the master and slave first connect; the other is to perform incremental synchronization after full synchronization is completed.
Full copy: The master server will start a background process to generate an rdb file from Redis data. The master server will cache all received write commands from the client. When the process is saved in the background, it will The rdb file is passed to the slave server. At this time, the slave server has the data of the master server. After this, the master server will send the cached commands during this period to the slave server through the redis transmission protocol, and then the slave server will use these commands on its own local in turn, eventually achieving data consistency
Incremental replication: The master node will continue to write commands. When the slave completes initialization and starts working, the process of the master server sending write operations to synchronize them to the server is called incremental replication. Incremental replication means that every time the server executes a write command, it sends the same write command to the slave server, and the slave server accepts and executes the received write command.
What are the characteristics of master-slave replication:
Master-slave replication is non-blocking for the master/slave server, and all data is synchronized During this period, external requests can be processed normally. A master node can contain multiple slave nodes, and each slave node can accept connections from other slave nodes. The slave node will not let the key expire. Instead, after the key of the master node expires and is deleted, it will send a delete command to the slave node to delete it.
Accelerated replication: When the node completes resynchronization, you need to create an RDB file on the disk, and then load this file to send data from the server, but what if the disk speed is relatively low? This will cause data inconsistency between the master node and the slave node. In the new version of Redis, disk-less replication is supported, and RBD files are directly sent to the slave server through the network, without using disks as middleware.
If the master-slave connection is disconnected, replication can be continued from the interrupted point after reconnection without resynchronization. After version 2.8, this new feature of resynchronization uses the PSYNC command, while the old one uses the SYNC command
For more programming-related knowledge, please visit:Programming Video! !
The above is the detailed content of Let's talk about the master-slave replication architecture in Redis6 and see what its characteristics are!. For more information, please follow other related articles on the PHP Chinese website!

Redis plays a key role in data storage and management, and has become the core of modern applications through its multiple data structures and persistence mechanisms. 1) Redis supports data structures such as strings, lists, collections, ordered collections and hash tables, and is suitable for cache and complex business logic. 2) Through two persistence methods, RDB and AOF, Redis ensures reliable storage and rapid recovery of data.

Redis is a NoSQL database suitable for efficient storage and access of large-scale data. 1.Redis is an open source memory data structure storage system that supports multiple data structures. 2. It provides extremely fast read and write speeds, suitable for caching, session management, etc. 3.Redis supports persistence and ensures data security through RDB and AOF. 4. Usage examples include basic key-value pair operations and advanced collection deduplication functions. 5. Common errors include connection problems, data type mismatch and memory overflow, so you need to pay attention to debugging. 6. Performance optimization suggestions include selecting the appropriate data structure and setting up memory elimination strategies.

The applications of Redis in the real world include: 1. As a cache system, accelerate database query, 2. To store the session data of web applications, 3. To implement real-time rankings, 4. To simplify message delivery as a message queue. Redis's versatility and high performance make it shine in these scenarios.

Redis stands out because of its high speed, versatility and rich data structure. 1) Redis supports data structures such as strings, lists, collections, hashs and ordered collections. 2) It stores data through memory and supports RDB and AOF persistence. 3) Starting from Redis 6.0, multi-threaded I/O operations have been introduced, which has improved performance in high concurrency scenarios.

RedisisclassifiedasaNoSQLdatabasebecauseitusesakey-valuedatamodelinsteadofthetraditionalrelationaldatabasemodel.Itoffersspeedandflexibility,makingitidealforreal-timeapplicationsandcaching,butitmaynotbesuitableforscenariosrequiringstrictdataintegrityo

Redis improves application performance and scalability by caching data, implementing distributed locking and data persistence. 1) Cache data: Use Redis to cache frequently accessed data to improve data access speed. 2) Distributed lock: Use Redis to implement distributed locks to ensure the security of operation in a distributed environment. 3) Data persistence: Ensure data security through RDB and AOF mechanisms to prevent data loss.

Redis's data model and structure include five main types: 1. String: used to store text or binary data, and supports atomic operations. 2. List: Ordered elements collection, suitable for queues and stacks. 3. Set: Unordered unique elements set, supporting set operation. 4. Ordered Set (SortedSet): A unique set of elements with scores, suitable for rankings. 5. Hash table (Hash): a collection of key-value pairs, suitable for storing objects.

Redis's database methods include in-memory databases and key-value storage. 1) Redis stores data in memory, and reads and writes fast. 2) It uses key-value pairs to store data, supports complex data structures such as lists, collections, hash tables and ordered collections, suitable for caches and NoSQL databases.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software