当前位置:网站首页>Redis cluster
Redis cluster
2022-07-19 08:10:00 【Program three two lines】
One 、 summary
stand-alone redis The problem is
Capacity is insufficient , a redis Insufficient capacity when writing data ?
Concurrency issues , a redis There is a concurrency problem when writing data ?
In master-slave mode , Host downtime or master-slave modification , Need to be in redis Revision in China ip The address is troublesome
redis3.0 The former is through host agent ,3.0 The non centralized cluster configuration is recommended
Two 、 build
Create a myredis Folder ( Here, you can simulate multiple servers by modifying multiple configuration file ports ) Copy redis.conf file 6 Share

The contents of each document are as follows ( Each file port is different )
include /myredis/redis.conf pidfile "/var/run/redis_6379.pid" port 6379 dbfilename "dump6379.rdb" cluster-enabled yes cluster-config-file nodes-6379.conf cluster-node-timeout 15000
start-up 6 individual redis see

Check the current directory file again , You can see that the corresponding node configuration file has been generated

Put six redis Compose a cluster
Get into redis Location
cd /opt/redis-6.2.1/src redis-cli --cluster create --cluster-relicas 1 192.168.10:6379 192.168.10:6389 192.168.10:6380 192.168.10:6381 192.168.10:6390 192.168.10:6391
explain :
- A cluster has at least three primary nodes
- relicas 1 It means to build a cluster in the simplest way That is, one master and one cluster just 3 Group
- The allocation principle tries to ensure that each master database runs on different servers ip Address , Each slave library and master library are not in one ip Address
Running effect

Connect to the cluster and see
redis-cli -c -p 6379 # Any port is ok cluster nodes

3、 ... and 、 slot
The above first 2 After clicking the synthesis, you can see the final output of the following sentence
All 16384 slots covered
One redis The cluster contains 16384 Slots , Every key in the database belongs to this 16384 One of the slots .
The cluster uses the formula CRC16(key)%16384 To calculate the key key Which slot does it belong to , among CRC16(key) Statements are used to evaluate keys key Of CRC16 Inspection and
Each node in the cluster is responsible for processing a portion of the slots , Let's take an example , If a cluster can have a master node , among :
A Nodes are responsible for handling 0 No. to 5460 Slot number
B Nodes are responsible for handling 5461 to 10922 Slot number
C Nodes are responsible for handling 10923 to 16383 Slot number
Test insert a pair key-value, There are obvious slot assignments

But if you insert multiple pairs key-value Problems arise

The above problems can be solved by grouping , Use the following user grouping

Check the slot key Corresponding slot value
cluster keyslot k1
Count slots key The number of
cluster countkeysinslot 4837
View the value of the specified number in the slot
cluster getkeysinslot 449 10
Four 、 Cluster failover
1、 If you go offline through the master node ? Whether the slave node can be automatically promoted to the master node ?15 Second timeout
Hang up 6379 You can see 6389 Become a host , When 6379 Recovery automatically becomes 6389 Slave

2、 A node in the cluster Both master and slave are down
If the master and slave of a certain slot hang up , and cluster-require-full-coverage by yes, Then the whole cluster will hang up , The master and slave of a slot in ancient China are all hung up , Two cluster-require-full-coverage by no, Then all the data in this slot cannot be used or stored
5、 ... and 、jedis Cluster development
redis Decentralization adopted . Even if the host is not connected , The cluster automatically switches host storage , Host write Read from machine , No matter which host writes data , Other hosts can read data

边栏推荐
- Redis storage structure principle 2
- Virtual machine stack of [JVM]
- 半导体材料技术
- Go language Bible
- How did "leek" give money to "sickle"? 2020-03-07
- Jd.com's purchase intention forecast (III)
- Ruffian Heng embedded bimonthly issue 58
- By voting for the destruction of STI by Dao, seektiger is truly community driven
- the max_iter was reached which means the coef_ did not converge “the coef_ did not converge“
- openvino机器学习初体验
猜你喜欢

redis消息订阅

串口通讯到底有没有累积误差及对时钟精度的要求

From the casino logic, analyze the investment value of platform currency 2020-03-03

FMC sub card: 4-way sfp+ 10 Gigabit optical fiber network FMC sub card

神经网络和自动控制的联系

Xinlinx zynq7020, 7045 domestic replacement fmql45t900 national production arm core board + expansion board

First experience of openvino machine learning

【刷题篇】完全平方数

Wechat oauth2.0 login process and security analysis

经典通用的Pbootcms花卉网站模板源码,自适应手机端,带后台管理
随机推荐
网站漏洞修复服务商分析可控参数带来的越权
Visual studio production environment configuration scheme: slowcheetah
How to choose the right model
C#对txt文件的读写操作
redis集群
How did "leek" give money to "sickle"? 2020-03-07
Database review -- database recovery technology
看完代码回首看论文:YOLOv3重读
没那么大的组合数
[day01] preface, introductory program, constant variables
深度学习之 7 深度前馈网络
【JVM】之虚拟机栈
Niuke topic - house raiding 1, house raiding 2
openvino机器学习初体验
xgboos-hperopt
Ruffian Heng embedded bimonthly issue 58
Junit5
How to check whether the app has user information and data leakage vulnerabilities
RISC-V技术杂谈
175. Combine two tables (MySQL database connection)