当前位置:网站首页>Redis cluster
Redis cluster
2022-07-08 01:26:00 【beginnerDZ】
Redis colony
Concept
Not enough capacity ,redis How to expand ?
1. Changing one set to multiple sets can solve colony
Concurrent write operations , redis How to apportion ?
1. colony
in addition , A master-slave mode , Pass on mode , Host down , Lead to ip The address has changed , The corresponding host address needs to be modified for configuration in the application 、 Port and other information .
Previously, it was solved by proxy host , however redis3.0 The solution . That is, decentralized cluster configuration .
Proxy host : A proxy is used between the client and the server It is different from the agent Redis The server sends the request receive data

shortcoming : There are many servers Inconvenient maintenance
No center :
Request to call the cluster , Automatically transfer to the target server
3 Lord 3 from

Redis The cluster has realized to Redis Horizontal expansion of , Start now N individual redis node , The entire database is distributed and stored here N A node in the , Each node stores the total data 1/N.
Redis Clusters are partitioned (partition) To provide a certain degree of usability (availability): Even if some nodes in the cluster fail or fail to communicate , The cluster can also continue to process command requests .
To configure
Turn on daemonize yes
Pid File name
Designated port
Log File name
Dump.rdb name
Appendonly Turn it off or change the name
In profile :
cluster-enabled yes Open cluster mode
cluster-config-file nodes-6379.conf Set the node profile name
cluster-node-timeout 15000 Set the node loss time , Beyond that time ( millisecond ), The cluster automatically switches between master and slave .
With 6 For example 6 Ports simulation 6 Servers
3678 Port of , Other ports are the same as the following, just change the number

start-up 6 individual redis Before service composition , Please make sure that all redis After the instance is started ,nodes-xxxx.conf All files are generated normally
The new version (6.2) There is no need to install ruby Environmental Science
Go to start installation redis Of src Next

Execute... Under this path
redis-cli --cluster create --cluster-replicas 1 192.168.200.130:6379 192.168.200.130:6380 192.168.200.130:6381 192.168.200.130:6389 192.168.200.130:6390 192.168.200.130:6391
6 A cluster of nodes
- –cluste Indicates cluster operation
- –cluster-replicas The way of clustering 1 It means the simplest way to configure the cluster , A mainframe , One slave , At present, there are exactly three groups .2 Namely A mainframe , Two slaves
Don't use it here 127.0.0.1, Please use real IP Address

Master and slave have been assigned . Accept or not
[OK] All 16384 slots covered.
redis-cli -c -p 6379 -c Use cluster policy to connect , The setting data will be automatically switched to the corresponding write host
cluster nodes View cluster information 
What is? slots
Cluster building completed There's a hint

One Redis The cluster contains 16384 Slots (hash slot), Every key in the database belongs here 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 The checksum .
Each node in the cluster is responsible for processing a portion of the slots . for instance , If a cluster can have a master node , among :
node A Responsible for handling 0 No. to 5460 Slot number .
node B Responsible for handling 5461 No. to 10922 Slot number .set
node C Responsible for handling 10923 No. to 16383 Slot number .
Not in one slot Key values under , Can't use mget,mset Wait for multi key operation .
Multiple values added Braces are required . Can pass {} To define the concept of a group , So that key in {} Key value pairs with the same content in a slot In the middle .
mset <key1><value1><key2><value2>
mset name{user} aa age{user} 20
CLUSTER keyslot X Calculation x Slot value for
CLUSTER countkeysinslot <slot> Calculate the number of keys in this card slot ( Only those within the corresponding range of the current library , If it's another library , Returns the 0)
CLUSTER GETKEYSINSLOT <slot><count> return count individual slot Key in groove .

Fault recovery
If the master node goes offline G 了 The slave node is automatically promoted to the master node Be careful :15 Second timeout
When the master node comes back, it will become a slave .
If the master and slave of a certain slot (6 Hang up 2 individual ) All hang up , and cluster-require-full-coverage by yes , that , The whole cluster is down
If the master and slave of a certain slot hang up , and cluster-require-full-coverage by no , that , None of the slot data is available , Can't store .
Jedis Related operations of
Even if the host is not connected , The cluster automatically switches host storage . Host write , Read from machine .
Decentralized master-slave cluster . No matter which host the data is written from , Data can be read on other hosts .
public class JedisClusterTest {
public static void main(String[] args) {
// Set<HostAndPort> set =new HashSet<HostAndPort>();
// //HostAndPort Any one will do Each can be used as the entrance of the cluster
// set.add();
JedisCluster jedisCluster=new JedisCluster(new HostAndPort("192.168.200.130",6379)); // Pass in set Or a HostAndPort Fine
jedisCluster.set("bbb1", "v111");
System.out.println(jedisCluster.get("bbb1"));
}
}
Advantages and disadvantages
Redis Clustering provides the following benefits
Realize capacity expansion
Apportionment pressure
No central configuration is relatively simple
Redis The lack of clustering
Multi key operation is not supported
Multibond Redis Transactions are not supported .lua Scripts are not supported
Due to the late emergence of the cluster scheme , Many companies have adopted other clustering schemes , The proxy or client partition scheme wants to migrate to redis cluster, Overall migration is required rather than gradual transition , High complexity .
边栏推荐
- 130. 被圍繞的區域
- 2022 operation certificate examination for main principals of hazardous chemical business units and main principals of hazardous chemical business units
- Markdown learning (entry level)
- Using GPU to train network model
- Study notes of single chip microcomputer and embedded system
- [deep learning] AI one click to change the sky
- Understanding of prior probability, posterior probability and Bayesian formula
- HDMI to VGA acquisition HD adapter scheme | HDMI to VGA 1080p audio and video converter scheme | cs5210 scheme design explanation
- Smart agricultural technology framework
- 10. CNN applied to handwritten digit recognition
猜你喜欢

Share a latex online editor | with latex common templates

Chapter VIII integrated learning

Basic realization of line graph

Redis 主从复制

Y59. Chapter III kubernetes from entry to proficiency - continuous integration and deployment (III, II)

Generic configuration legend

Cs5212an design display to VGA HD adapter products | display to VGA Hd 1080p adapter products

4. Apprentissage stratégique

2022 safety officer-a certificate free examination questions and safety officer-a certificate mock examination

2022 high altitude installation, maintenance and demolition examination materials and high altitude installation, maintenance and demolition operation certificate examination
随机推荐
Gnuradio transmits video and displays it in real time using VLC
Arm bare metal
Scheme selection and scheme design of multifunctional docking station for type C to VGA HDMI audio and video launched by ange in Taiwan | scheme selection and scheme explanation of usb-c to VGA HDMI c
Two methods for full screen adaptation of background pictures, background size: cover; Or (background size: 100% 100%;)
Know how to get the traffic password
2022 safety officer-a certificate free examination questions and safety officer-a certificate mock examination
130. Surrounding area
Parade ps8625 | replace ps8625 | EDP to LVDS screen adapter or screen drive board
The difference between distribution function and probability density function of random variables
Apt get error
2021-03-06 - play with the application of reflection in the framework
Mathematical modeling -- knowledge map
USB type-C mobile phone projection scheme | USB type-C docking station scheme | TV / projector type-C converter scheme | ag9300ag9310ag9320
npm 內部拆分模塊
Kuntai ch7511b scheme design | ch7511b design EDP to LVDS data | pin to pin replaces ch7511b circuit design
2022 refrigeration and air conditioning equipment operation examination questions and refrigeration and air conditioning equipment operation examination skills
Taiwan Xinchuang sss1700 latest Chinese specification | sss1700 latest Chinese specification | sss1700datasheet Chinese explanation
Basic realization of line chart (II)
Smart grid overview
Common operations of numpy on two-dimensional array