Consistent hash algorithm realizes redis cluster sharding

Recently, the company plans to do redis cluster sharding, and researched that the clutesr function that comes with redis is really powerful. The only drawback is that when one of the sharded servers dies, the entire cluster will go down and the system will be unavailable.

The official solution is: Redis needs to build a master-slave configuration scheme for each shard when building a cluster sharding service, so that it can be automatically switched to solve related problems, but the master-slave configuration needs to build a redis sentinel sentinel service, which leads to the whole The cluster is becoming more and more complex and the maintenance cost is getting higher and higher. Therefore, to solve this problem in the future, we plan to implement this function through client sharding to reduce operation and maintenance pressure.

Looking through the information, I found that java has a ready-made jredis client sharding scheme, and C# can only implement it by itself. Backup achieves the purpose of backup by hashing the key value twice

So what is a consistent hashing algorithm? There is a lot of information on the Internet. I will talk about my understanding while the cold rice is cooking.

Redis is a database for key-value pair data storage. When we want to distribute the data evenly on multiple servers when storing data, we need an algorithm, namely a consistent hashing algorithm.

What is a consistent hashing algorithm, I will not go into details again. There are a lot of information on the Internet. For the specific algorithm code, see
https://git.oschina.net/hl.wei/RedisCluster.git
Consistent Hash Algorithm It is possible to achieve data hashing to a balanced server, which can maximize the impact of data hashing problems when increasing or decreasing servers. However, there is a more stable way to achieve this problem.
We have A, B, C. Three servers, we build three redis instances on the three servers every day, which is equivalent to creating 9 redis instances, so that when we add a new machine, we can directly map a server to one of the instances, and the server data Carry out migration to achieve the purpose of perfect data migration with zero error,

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324982682&siteId=291194637