当前位置:网站首页>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 .
边栏推荐
- Redis集群
- Guojingxin center "APEC investment +": some things about the Internet sector today | observation on stabilizing strategic industrial funds
- 130. 被圍繞的區域
- A speed Limited large file transmission tool for every major network disk
- Content of one frame
- Vscode is added to the right-click function menu
- 3. MNIST dataset classification
- 2022 R1 fast opening pressure vessel operation test question bank and R1 fast opening pressure vessel operation free test questions
- Understanding of maximum likelihood estimation
- 2022 free test questions of fusion welding and thermal cutting and summary of fusion welding and thermal cutting examination
猜你喜欢
130. 被圍繞的區域
2022 free test questions of fusion welding and thermal cutting and summary of fusion welding and thermal cutting examination
Common configurations in rectangular coordinate system
The communication clock (electronic time-frequency or electronic time-frequency auxiliary device) writes something casually
EDP to LVDS conversion design circuit | EDP to LVDS adapter board circuit | capstone/cs5211 chip circuit schematic reference
Redis集群
2022 examination for safety production management personnel of hazardous chemical production units and new version of examination questions for safety production management personnel of hazardous chem
Gnuradio3.9.4 create OOT module instances
Know how to get the traffic password
Recommend a document management tool Zotero | with tutorials and learning paths
随机推荐
Generic configuration legend
2022 R1 fast opening pressure vessel operation test question bank and R1 fast opening pressure vessel operation free test questions
Different methods for setting headers of different pages in word (the same for footer and page number)
130. Zones environnantes
Ag9310meq ag9310mfq angle two USB type C to HDMI audio and video data conversion function chips parameter difference and design circuit reference
Frrouting BGP protocol learning
2022 safety officer-c certificate examination paper and safety officer-c certificate simulated examination question bank
2022 safety officer-c certificate examination summary and safety officer-c certificate reexamination examination
Study notes of single chip microcomputer and embedded system
Design method and reference circuit of type C to hdmi+ PD + BB + usb3.1 hub (rj45/cf/tf/ sd/ multi port usb3.1 type-A) multifunctional expansion dock
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
FIR filter of IQ signal after AD phase discrimination
Swift get URL parameters
Chapter 7 Bayesian classifier
Parade ps8625 | replace ps8625 | EDP to LVDS screen adapter or screen drive board
Multi purpose signal modulation generation system based on environmental optical signal detection and user-defined signal rules
Common operations of numpy on two-dimensional array
Introduction to the types and repair methods of chip Eco
Leetcode notes No.21
[loss function] entropy / relative entropy / cross entropy