Home  >  Article  >  Database  >  redis cluster principle

redis cluster principle

(*-*)浩
(*-*)浩Original
2019-06-03 16:52:429441browse

Redis is a typical no-sql, that is, non-relational database that stores key-value pairs like a python dictionary and works in memory

, so it is very suitable to serve as the entire Internet architecture The cache between the various levels, such as the 4-layer forwarding layer of lvs and the 7-layer proxy layer of nginx

redis cluster principle

, especially the lnmp architecture application layer such as php-fpm or Tomcat to mysql Create a cache between them to reduce the pressure on the db

Because a considerable part of the data is just a simple key-value correspondence, and in actual business, it often changes rapidly in a short period of time

If you use a relational database such as mysql for storage, it will greatly increase the access to the db and cause a heavy burden on the db. Because most of all the requirements will eventually converge to the db

, so if you want business stability, then solve the db The pressure is the key, so most of the solutions now are to use multi-level no-sql at all levels above the db layer

Like memcache redis, etc. to provide buffering for the db

Redis Cluster

Redis cluster is a facility installation that can share data between multiple Redis nodes.

Redis cluster does not support those Redis commands that need to process multiple keys at the same time, because executing these commands requires moving data between multiple Redis nodes, and under high load, these commands will slow down the Redis cluster. performance, and cause unpredictable behavior.

Redis cluster provides a certain degree of availability through partitioning: even if some nodes in the cluster fail or cannot communicate, the cluster can continue to process command requests.

Redis cluster provides the following two benefits:

The ability to automatically split data into multiple nodes.

When some nodes in the cluster fail or cannot communicate, they can still continue to process command requests.

Cluster Principle

All redis nodes are interconnected with each other (PING-PONG mechanism), and the binary protocol is used internally to optimize transmission speed and bandwidth.

The fail of a node takes effect only when more than half of the nodes in the cluster detect failures.

The client is directly connected to the redis node, without the need for an intermediate proxy layer. The client does not need to connect to all nodes in the cluster, just connect to any available node in the cluster.

redis-cluster maps all physical nodes to [0-16383] slot, and cluster is responsible for maintaining node<->slot<->value

16384 is built into the Redis cluster A hash slot, when a key-value needs to be placed in the Redis cluster, redis first uses the crc16 algorithm to calculate a result for the key, and then calculates the remainder of the result to 16384, so that each key will correspond to a number between 0-16383 Hash slots between, redis will map the hash slots to different nodes roughly equally according to the number of nodes

The above is the detailed content of redis cluster principle. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn