Implementation of Redis multi-host database and redis Database

Source: Internet
Author: User
Tags redis cluster

Implementation of Redis multi-host database and redis Database

1. Copy

In Redis, You can execute the SLAVEOF command or set the slaveof option to let one server copy another server. We call the copied server as the master server ), the server that copies the master server is called the slave server ).


Assume that there are two Redis servers at 127.0.0.1: 6379 and 127.0.0.1: 12345 respectively. If we send the following command to the server 127.0.0.1: 12345:

127.0.0.1: 12345> SLAVEOF127.0.0.1 6379

Then the server 127.0.0.1: 12345 will become the slave server of 127.0.0.1 6379, and the server 127.0.0.1 6379 will become the master server of 127.0.0.1: 12345.

Databases on both master and slave servers in the replication process will save the same data. This phenomenon is called "database status consistency ". You can run SET on the master server to obtain the value from the slave server.

Partial re-synchronization is implemented by copying the offset, copying the backlog buffer, and the server running ID.

At the beginning of the replication operation, the slave server will become the master server client and execute the replication step by sending a command request to the master server, the master and slave servers become the clients of each other.

The master server updates the status of the slave server by spreading commands to the slave server to ensure consistency between the master and slave servers. The slave server sends commands to the master server for heartbeat detection and command loss detection.

Ii. Sentinel

Sentinel is a Redis high availability solution. A Sentinel system consisting of one or more Sentinel instances can monitor any number of Master servers, and all slave servers under the master server. When the monitored master server goes offline, it automatically upgrades a slave server under the master server to a new master server, then, the new master server replaces the offline master server to continue processing command requests.

Sentinel is only a Redis server running in special mode. It uses a command table different from the common mode. Therefore, the commands available in Sentinel mode are different from those available in the common Redis server.

 

Iii. Clusters

Redis cluster is a distributed database solution provided by Redis. The cluster shares data through sharding and provides the replication and Failover functions.

For example, if a cluster contains three nodes: 7000, 7001, and 7002, the figure shows the entire handshake process of the three nodes.


The 16384 slots in the cluster can be assigned to each node in the cluster. Each node records the slots assigned to it. When receiving a command request, the node first checks whether the slot of the key to be processed in this command request is the responsibility of itself. If not, the node returns a MOVED error to the client, the information carried by MOVED errors can direct the client to the node responsible for the relevant slot.

Redis-trib is responsible for re-sharding of redis clusters. The key of re-sharding is to transfer all key-value pairs belonging to a certain slot from one node to another.

If node A is migrating slot I to Node B, when node A fails to find the database key specified by the command in its own database, node A will return A ASK error to the client, directs the client to Node B to continue searching for the specified database key.

The MOVED error indicates that the owner of the slot has been transferred from one node to another. The ASK error is only a temporary measure used by the two nodes during the slot migration.

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.