Redis cluster function Overview

Source: Internet
Author: User
Tags failover redis cluster

Redis replication features and redis sentinel and twemproxy are introduced in single-host redis, where:

Copy: You can create copies of a specified server.Extended system's ability to process read requests;

Redis Sentinel: Based on the replication feature, you can monitor the master and slave servers and when the master server fails.Perform automatic failoverTo ensure the availability of the system;

Twemproxy: The sharding policy is used to divide the database into multiple different servers.Extended Data volume stored by the SystemAnd distribute command requests to different servers for processing.Extends the system's ability to process command requests;

However, the above features are independent. If we need a complete redis server cluster that includes replication, high availability, and sharding features, we need to use the redis cluster feature;

 

Redis Cluster

Implementation of redis Distributed Database

Distributed

A redis cluster is a distributed network server group composed of multiple redis servers. Each server in the cluster is called a node.Connect and communicate with each other;

Distributed redis ClusterNo central nodeTherefore, you do not have to worry that a node will become the performance bottleneck of the entire cluster;

Copy

Each node of the redis cluster has two optional roles: master node and slave node. The master node is used to store data, slave nodes are copies of a master node;

When you need to process more requests, adding slave nodes can expand the system's read performance. Because redis clusters reuse the single-host redis replication feature, the cluster replication behavior is exactly the same as the single-host replication behavior;

Add a slave node for each master node:

Node Fault Detection and automatic failover

The master node of the redis cluster has built-in node Fault Detection and automatic failover functions similar to redis Sentinel. When a master node in the cluster is offline, other online master nodes in the cluster will notice this, failover is performed on the active node that has been deprecated;

The cluster failover method is basically the same as the redis sentinel failover method. The difference is that in the cluster, failover is performed by other online master nodes in the cluster, therefore, the cluster does not need to use redis Sentinel.

For example, when 7000 goes offline, 7001 and 7002 will be aware of this and fail over 7000.

Parts

The cluster uses shards to expand the database capacity and hand over the load of command requests to different nodes for sharing;

The cluster divides the database into 16384 slots. All the keys belong to one of the 16384 slots. The formula for which the computing key belongs is slot_number = crc16 (key) % 16384, where crc16 is a 16-bit Cyclic Redundancy checksum function;

Each master node in the cluster can process 0 to 16384 slots. When a node in 16384 slots is responsible for processing, the cluster goes online, and start to process the data command request sent by the client;

Example:

There are three master nodes 7002, And, so:

Assign slots 0 to 5460 to node 7000 for processing;

Assign slot 5461 to node 10922 for processing;

Assign slot 10923 to node 16383 for replication;

In this way, the 16384 slots can be evenly assigned to three nodes for processing;

Redirection

For a master node assigned a slot, this master node only processes command requests assigned to its own slot;

If a node receives a command unrelated to its own processing slot, the node will report a redirection error to the client, telling the client which node is responsible for processing the command, then, the client needs to re-send a command request to the correct Node Based on the address and port number contained in the error;

 

Redis cluster function Overview

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.