zeromicro / go-zero

A cloud-native Go microservices framework with cli tool for productivity.
https://go-zero.dev
MIT License
28.25k stars 3.84k forks source link

redis cluster/consistent hash #4001

Open plum330 opened 3 months ago

plum330 commented 3 months ago

In redis cluster mode, go-redis can calculate the hash slot where the key resides and route it to the selected node. Why still need consistent hash?

MarkJoyMa commented 3 months ago

The purpose of this implementation is to save costs, because the redis network bandwidth on Alibaba Cloud is linked to capacity. If you use a larger bandwidth, you can only upgrade the redis specifications. However, in some cases, your business does not need such a large bandwidth. redis capacity, then you can choose to use several small redis combinations. We saved 8 times the cost by using this method.

plum330 commented 3 months ago

The purpose of this implementation is to save costs, because the redis network bandwidth on Alibaba Cloud is linked to capacity. If you use a larger bandwidth, you can only upgrade the redis specifications. However, in some cases, your business does not need such a large bandwidth. redis capacity, then you can choose to use several small redis combinations. We saved 8 times the cost by using this method.

Are these small capacity redis selected to form a cluster a shard cluster? If it is not a sharded cluster, how is the node change data migration implemented?

plum330 commented 3 months ago

Other question, why not just use codis? thx @MarkJoyMa

MarkJoyMa commented 3 months ago

The purpose of this implementation is to save costs, because the redis network bandwidth on Alibaba Cloud is linked to capacity. If you use a larger bandwidth, you can only upgrade the redis specifications. However, in some cases, your business does not need such a large bandwidth. redis capacity, then you can choose to use several small redis combinations. We saved 8 times the cost by using this method.

Are these small capacity redis selected to form a cluster a shard cluster? If it is not a sharded cluster, how is the node change data migration implemented?

Why do you need to migrate? If there are new or reduced nodes in the cache cluster, just re-obtain the db normally. This is only used as a cache.

MarkJoyMa commented 3 months ago

Other question, why not just use codis

codis is a distributed Redis solution. It is not equivalent to the cache here. In other words, the capabilities provided by the cache are functionally equivalent to the sharding logic of codis. It does not provide a distributed Redis solution.

MarkJoyMa commented 3 months ago

Another point, we have to pay attention to a core issue, what is the purpose of the cache array here? It is not to solve the redis distribution problem, but to achieve the purpose of cost control. As for using redis node cluster, codis or other redis solutions, it does not matter.