Home > Database > Redis > body text

How to create a cluster in redis

(*-*)浩
Release: 2019-11-20 15:05:52
Original
2456 people have browsed it

How to create a cluster in redis

Redis Sharding Cluster

Redis 3 officially launched the official cluster technology to solve the problem of collaborative service of multiple Redis instances. Redis Cluster can be said to be the embodiment of server-side Sharding technology, which means that key values ​​are reasonably allocated to each instance shard according to a certain algorithm. At the same time, each instance node coordinates and communicates to jointly provide consistent external services. (Recommended learning: Redis video tutorial)

Multiple Redis instance services are much more complex than single Redis instances, which involve technical problems such as positioning, collaboration, fault tolerance, and expansion. . Here, we introduce a lightweight client-side Redis Sharding technology.

Redis Sharding can be said to be a multi-Redis instance cluster method commonly used in the industry before Redis Cluster came out. The main idea is to use a hash algorithm to hash the key of Redis data. Through the hash function, a specific key will be mapped to a specific Redis node. In this way, the client knows which Redis node to operate data on.

Fortunately, the java redis client driver jedis already supports the Redis Sharding function, namely ShardedJedis and ShardedJedisPool combined with the cache pool.

The Redis Sharding implementation of Jedis has the following characteristics:

Uses consistent hashing algorithm (consistent hashing) to hash the key and node name at the same time, and then perform mapping and matching , the algorithm used is MURMUR_HASH.

The main reason for using consistent hashing instead of simple hash-like modulo mapping is that when nodes are added or reduced, rehashing due to rematching will not occur. Consistent hashing only affects the key allocation of adjacent nodes, and the impact is small.

In order to avoid consistent hashing only affecting adjacent nodes and causing node allocation pressure, ShardedJedis will virtualize 160 virtual nodes according to the name of each Redis node (no, Jedis will assign a default name). Hash.

According to the weight, virtual nodes that are multiples of 160 can also be virtualized. Using virtual nodes for mapping matching allows keys to be moved and distributed more evenly among Redis nodes when adding or reducing Redis nodes, instead of only adjacent nodes being affected.

ShardedJedis supports keyTagPattern mode, which is to extract a part of the keyTag for sharding. In this way, by naming the key appropriately, a group of related keys can be put into the same Redis node, which avoids accessing related data across nodes. Very important.

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template