当前位置:网站首页>Hash slot of rediscluster cluster cluster implementation principle
Hash slot of rediscluster cluster cluster implementation principle
2022-06-28 07:35:00 【Huangyuewang】
Redis Clusters use data fragmentation , Instead of consistent hashing , One Redis The cluster contains 16384 Hash slot (hash slot), Use set The stored data belongs to 16384 One of the hash slots , Cluster use crc16(key) % 16384 To calculate key Which slot does it belong to .
Illustrate with examples , Now we need to build Cluster colony 6 Nodes ,redis Of Port number In turn 7000,7001,7002,7003,7004,7005,6 Nodes are divided into 3 Group , A master (master) A congruent form
Here's the picture
Calculate the hash slot sorting for each group , Each group =16384/3=5461
that :
First set of ports 7000 The hash slot of is 0-5460
First set of ports 7001 The hash slot of is 5461-10922
First set of ports 7002 The hash slot of is 10923-16383
notes : The figure below is a bit wrong , I'm too lazy to redraw

Let's prepare for practical operation :
One , Cluster Cluster building
1, The first step is to be ready 8 individual redis.conf file
linux In the environment ,redis Deployed in /application Under the table of contents , First create a good 8 Directories execute the following commands :
cd /application
mkdir rediscluster
cd rediscluster/
mkdir redis7000
mkdir redis7001
mkdir redis7002
mkdir redis7003
mkdir redis7004
mkdir redis7005
# Then dynamically add to the hash slot
mkdir redis7006
mkdir redis7007A copy of redis.conf, Modify the following :
dbfilename 7000dump.rdb
daemonize yes # Background start
protected-mode no ; ## Allow external access
port 7000 # Modify port number , from 7000 To 7007
cluster-enabled yes # Turn on cluster, Remove annotations
cluster-config-file 7000nodes.conf # Automatic generation
cluster-node-timeout 15000 # Node communication time
logfile /application/rediscluster/redis7000/redis.log"/application/rediscluster/redis7000/redis.log"Then the file is copied 8 Share , Modify the above contents in turn , Change it and put it in the corresponding folder .
Pay attention to the upper band 7000-7007 It's the port number , Each folder corresponds to the corresponding port number , for example :redis7005 In a folder redis.conf The content corresponds to
dbfilename 7005dump.rdb
port 7005 # Modify port number , from 7000 To 7007
cluster-config-file 7005nodes.conf # Automatic generation
logfile /application/rediscluster/redis7005/redis.log"/application/rediscluster/redis7005/redis.log"give the result as follows :


2, The second step , start-up 6 individual redis
/application/redis/bin/redis-server /application/rediscluster/redis7000/redis.conf
/application/redis/bin/redis-server /application/rediscluster/redis7001/redis.conf
/application/redis/bin/redis-server /application/rediscluster/redis7002/redis.conf
/application/redis/bin/redis-server /application/rediscluster/redis7003/redis.conf
/application/redis/bin/redis-server /application/rediscluster/redis7004/redis.conf
/application/redis/bin/redis-server /application/rediscluster/redis7005/redis.confCheck the process :ps -ef|grep redis

notes : No hash slot is allocated set operation , Because the data is stored in the hash slot , I haven't been assigned how to write ?
3, The third step , Assign hashico
/application/redis/bin/redis-cli --cluster create 172.16.166.122:7000 172.16.166.122:7001 172.16.166.122:7002 172.16.166.122:7003 172.16.166.122:7004 172.16.166.122:7005 --cluster-replicas 1The following figure will pop up after execution , Ask whether to set the above configuration ? Input yes

This completes the allocation of hash slots
4, Step four , View the assigned Hashi slots
First connect to 7000 Port node
#172.16.166.122 It's the intranet IP
/application/redis/bin/redis-cli -h 172.16.166.122 -p 7000 -cEnter the command : cluster nodes

You can see that there is 3 Group master, Only master To allocate Hashi slots , The cluster will automatically conduct the election , Here's the picture 7000,7001,7002 yes master node ,7000 The slave node of is 7004, Maybe some friends built it according to the above figure 7000 The children of are 7003, It's all possible , The result of the election shall prevail

7000 and 7004 How nodes are associated ? Look at the picture below to see the answer

Test cluster :
Test write operation :
# Connect to cluster
/application/redis/bin/redis-cli -h 172.16.166.122 -p 7000 -ctest set aaa 1 Data stored in [10439] Hash slot , Belong to 7001 node
test set bbb 2 Data stored in [5287] Hash slot , Belong to 7000 node

Test read operation :
test get aaa from 7001 Hashi slot of node [10439] To find the key The result is 1

边栏推荐
- Kubelet garbage collection (exiting containers and unused images) source code analysis
- Ice - resources
- The practice of traffic and data isolation in vivo Reviews
- Source code analysis of kubernetes' process of deleting pod
- R 语言 Hitters 数据分析
- HTTP Caching Protocol practice
- What is the lifecycle of automated testing?
- [thanos source code analysis series]thanos query component source code analysis
- Construction and exploration of vivo database and storage platform
- PLC -- Notes
猜你喜欢

8 张图 | 剖析 Eureka 的首次同步注册表

在idea中,get和set方法爆红可能是没有安装Lombok插件

异或的应用。(提取出数字中最右侧的1,面试中经常用的到)

No suspense about the No. 1 Internet company overtime table

Tencent continued to lay off staff in the second half of the year, and all business groups reduced by at least 10%. What do you think of this? Followers

Mysql57 zip file installation

Using interceptor and cache to complete interface anti brushing operation

Vivo browser rapid development platform practice - Overview

Block transmission by golang gin framework

Construction and exploration of vivo database and storage platform
随机推荐
Server body 18: understanding and thinking of UDP reliable transmission (feeling from reading Yunfeng blog)
Uninstall and reinstall the latest version of MySQL database. The test is valid
Using interceptor and cache to complete interface anti brushing operation
Code submission specification
Comment la passerelle BACnet / IP recueille - t - elle les données du système central de contrôle des bâtiments?
Vivo browser rapid development platform practice - Overview
mysql57 zip文件安装
Self discipline challenge 30 days
MMR rearrangement (similarity is calculated by editing distance and repeatability)
Real time database - Notes
2021 VDC: technological architecture evolution of vivo Internet service for 100 million users | PPT download attached
Top 25 most popular articles on vivo Internet technology in 2021
Can okcc call centers work without computers?
PLC -- 笔记
Is it safe for flush to open an account online
Kubernetes deploys a secret pit where thanos ruler sends repeated alarms
DBeaver 22.1.1 发布,可视化数据库管理平台
hack the box:RouterSpace题解
8 张图 | 剖析 Eureka 的首次同步注册表
腾讯下半年继续裁员,所有事业群至少缩减 10%,对此你怎么看?关注者