当前位置:网站首页>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 .
边栏推荐
- Vscode is added to the right-click function menu
- Problems of font legend and time scale display of MATLAB drawing coordinate axis
- Talk about smart Park
- npm 内部拆分模块
- Understanding of maximum likelihood estimation
- 3. MNIST dataset classification
- Leetcode notes No.21
- Smart agricultural technology framework
- Common effects of line chart
- Kindle operation: transfer downloaded books and change book cover
猜你喜欢
2022 chemical automation control instrument examination summary and chemical automation control instrument simulation examination questions
Vscode is added to the right-click function menu
Chapter XI feature selection
Four digit nixie tube display multi digit timing
14. Draw network model structure
7. Regularization application
4、策略學習
130. Zones environnantes
Chapter VIII integrated learning
2021 welder (primary) examination skills and welder (primary) operation examination question bank
随机推荐
Different methods for setting headers of different pages in word (the same for footer and page number)
14. Draw network model structure
The beauty of Mathematics -- the principle of fine Fourier transform
[loss function] entropy / relative entropy / cross entropy
Parade ps8625 | replace ps8625 | EDP to LVDS screen adapter or screen drive board
2021 Shanghai safety officer C certificate examination registration and analysis of Shanghai safety officer C certificate search
Kaptcha generates verification code on Web page
The difference between distribution function and probability density function of random variables
Cs5212an design display to VGA HD adapter products | display to VGA Hd 1080p adapter products
5、离散控制与连续控制
For the first time in China, three Tsinghua Yaoban undergraduates won the stoc best student thesis award
STM32GPIO口的工作原理
After modifying the background of jupyter notebook and adding jupyterthemes, enter 'JT -l' and the error 'JT' is not an internal or external command, nor a runnable program
Redis master-slave replication
Content of one frame
2022 safety officer-c certificate examination summary and safety officer-c certificate reexamination examination
Matlab code on error analysis (MAE, MAPE, RMSE)
How to get the first and last days of a given month
Connect to the previous chapter of the circuit to improve the material draft
About how USRP sets the sampling frequency below the minimum sampling frequency reached by the hardware