Redis must-know concepts for back-end development

Endurance

RDB persistence

RDB persistence refers to saving the data in the current process to the hard disk by generating a snapshot. The suffix of the saved file name is rdb. When Redis restarts, it will read the files in the snapshot to restore the data;

AOF persistence

AOF persistence refers to recording each command written in Redis into a separate log file; when Redis restarts, execute the command in the file again to restore the data; the Redis server turns on RDB by default and turns off AOF; to turn on AOF, you need to configured in the configuration file.

Advantages and Disadvantages of RDB and AOF

RDB persistence:

Advantages: RDB file size is small. The network transmission is fast, suitable for full copy, and the recovery speed is fast; the impact on performance is low; Disadvantages: the persistence of the implementation cannot be achieved, and data may be lost;

AOF persistence:

Advantages: real-time data persistence; Disadvantages: large files, slow recovery speed, large impact on performance;

master-slave replication

Master-slave replication refers to copying data on one redis server to other redis servers to ensure timely backup of data. The former is called the master node, and the latter is called the slave node.

Features

1. Data replication is one-way, and data can only be copied from the master node to the slave node; 2. A redis server can be used as a master node or a slave node; but a slave node can only have one master node. ;

effect

1. Data redundancy: Master-slave replication realizes hot backup of data. It is a data redundancy method other than persistence; 2. Fault recovery: Due to data backup, when a problem occurs on the master node, a slave node can temporarily provide services. It is a kind of redundancy in services; 3. High concurrency: We use the separation of reading and writing to assign different functions to the master node and the slave node. We can use the master node for writing data. The slave node is responsible for reading data. This can easily cope with high read concurrency in scenarios where there is more reading and less writing. We just need to deploy more slave nodes; 4. Foundation: The basis for sentinel and cluster implementation during master-slave replication.

sentinel

The core function of Sentinel is automatic failover of the master node.

Features

1. Monitoring: Sentinel will continuously detect whether the master node and slave nodes are operating normally; 2. Automatic failover: If the master node cannot work properly. It will upgrade one of the slave nodes in the failed master node to the new master node, and let other slave nodes change to replicate the new master node; 3. Configuration provider: Sentinel is responsible for the master node address of the Redis service ; 4. Notification: Sentinel can also send the failover results to the client;

Typical architecture diagram

It consists of two parts, sentinel nodes and data nodes:

  • Sentinel node: The sentinel system consists of one or more sentinel nodes. Sentinel nodes are special redis nodes that do not store data.
  • Data nodes: Both master nodes and slave nodes are data nodes.

Redis-Cluster cluster

The cluster is composed of multiple nodes (Node), and Redis data is distributed among these nodes. The nodes in the cluster are divided into master nodes and slave nodes: only the master node is responsible for read and write requests and maintenance of cluster information; the slave node only replicates the master node data and status information.

effect

1. Data partitioning: The cluster disperses data to multiple nodes. On the one hand, it breaks through the limit of Redis single-machine memory size and greatly increases the storage capacity. On the other hand, each master node can provide external read services and write services, which greatly improves the efficiency. Cluster responsiveness. 2. High availability: The cluster supports master-slave replication and automatic failover of the master node (similar to Sentinel); when any node fails, the cluster can still provide external services.

Benefits of this article,Receive it for freeLinux C/C++Full stack development learning package, technical videos /Code, 1000 Daochang interview questions, including (< /span>↓↓~ to get it927239107 kernel and other advanced learning materials and best learning roadmap) ↓↓↓↓If necessary, you can Enter Penguin SkirtLinuxDevelopment, game development,QtBasics, network programming, database, middleware, back-end development, audio and video development, C++

Guess you like

Origin blog.csdn.net/m0_60259116/article/details/134751794