Overview of Redis Cluster main components

来源:互联网 发布:新网站如何做优化 编辑:程序博客网 时间:2024/04/28 09:55

Keys distribution model

HASH_SLOT = CRC16(key) mod 16384

CRC16 behaved remarkably well in distributing different kind of keys evenly across the 16384 slots.
总之,该方法可以是数据均匀的分配不同的节点上。

Keys hash tags

>Hash tags are a way to ensure that multiple keys are allocated in the same hash slot. This is used in order to implement multi-key operations in Redis Cluster.

rules:

IF the key contains a { character.
AND IF there is a } character on the right of {
AND IF there are one or more characters between the first occurrence of { and the first occurrence of }.

Examples:

{user1000}.following > hash key “user1000”
{user1000}.followers > hash key “user1000”
foo{}{bar} > hash key “foo{}{bar}”
foo{{bar}} > hash key “{bar”
foo{bar}{zap} > hash key “bar”
{}noMatterWhat > hash key while key

tips: 对于二进制key,为了确保整个key都被用于hash,可以另key以“{}”开头。

Cluster nodes attributes

unique name

唯一,当配置文件删除或者强行reset才会改变。

Redirection and resharding

MOVED Redirection

客户端可以向集群中的任何一个节点发消息,包括从节点。
处理过程:
1.能否处理if it is acceptable (that is, only a single key is mentioned in the query, or the multiple keys mentioned are all to the same hash slot)
2.归谁处理(查询slot–>node map)
3.处理,归自己处理,归其他节点处理,执行move指令。
示例:-MOVED 3999 127.0.0.1:6381

0 0
原创粉丝点击