基于docker 部署redis cluster 生产集群

本文介绍了如何基于docker部署redis cluster生产集群,讨论了为何要建立redis cluster,集群搭建过程中的注意事项,包括节点数据同步问题、端口通信失败的解决,并提供了解决这些问题的具体操作步骤。最后展示了成功启动的集群状态及数据分布情况。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

开始之前我们提出几个问题:

什么是redis cluster ?

keyHashSlot 函数用来计算给定键应该被分配到哪个槽采用分片取模算法实现节点分配,节点数据存储。

/* --------------cluster.c---------------------------------------------------------------
 * Key space handling
 * -------------------------------------------------------------------------- */

/* We have 16384 hash slots. The hash slot of a given key is obtained
 * as the least significant 14 bits of the crc16 of the key.
 *
 * However if the key contains the {...} pattern, only the part between
 * { and } is hashed. This may be useful in the future to force certain
 * keys to be in the same node (assuming no resharding is in progress). */
 //我们有16384个哈希槽,将会用crc16得到的最小有效14位作为给定key的哈希槽。
 //但是,如果键包含‘{...}’这样的字段,只有在"{“和“}”之间的才会被哈希。这在将来可能有助于将某些键强制放在同一个节点中(假设没有进行重新分片
 
// 计算给定键应该被分配到哪个槽
unsigned int keyHashSlot(char *key, int keylen) {
    int s, e; /* start-end indexes of { and } */

    for (s = 0; s < keylen; s++)
        if (key[s] == '{') 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

嗨,您好

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值