当前位置:网站首页>Redirection of redis cluster
Redirection of redis cluster
2022-07-05 11:44:00 【We've been on the road】
This article mainly introduces redis Clustered Redirect problem .
One 、 The reason for redirection
about Redis In terms of clusters , Because cluster nodes can't proxy (proxy) Command request , So the client should return -MOVED
perhaps -ASK
to turn to (redirection) When it's wrong , Forward the command request to other nodes .
Common optimization methods in use : The client can save the mapping information between key and node , It can effectively reduce the number of possible turns , So as to improve the efficiency of command execution .
When a node needs to make a client long-term (permanently) When a command request for a slot is sent to another node , The node returns... To the client MOVED
to turn to . This situation is usually , When the client requests an operation that does not exist on the current node , We can usually solve this problem by maintaining a mapping relationship between nodes and key values on the client side .
On the other hand , When the node needs to let the client only move to another node in the next command request , The node returns... To the client ASK
to turn to . Here redirection is generally redis When data is being migrated between different nodes in the cluster , To use this ASK to turn to , for example redis When the cluster expands or shrinks .
Two 、MOVED to turn to
One Redis The client can go to any node in the cluster ( Include slave nodes ) Send command request . If the slot you are looking for is not handled by this node , The node will view the hash slot saved in itself to the node ID Mapping records for , And reply to the client with a MOVED
error .
( come from : https://www.huaweicloud.com/articles/38e2316d01880fdbdd63d62aa26b31b4.html)
Execution process :
-
1.Redis A single node of the socket Communications ,
-
Will share Redis Cluster The relationship between the slot and the corresponding node in the cluster .
-
2. Client to Redis Cluster Send commands to any node of the ,
-
The node receiving the command will respond to CRC16 Rules carry out
hash Operation and 16383 Remainder ,
-
Calculate your own slot and corresponding node .
-
3. If the slot that holds the data is assigned to the current node , Then execute the command in the slot ,
-
And return the result of command execution to the client .
-
4. If the slot where the data is stored is not within the management scope of the current node ,
-
Return... To the client moved Redirection exception .
-
5. The client receives the result returned by the node , If it is moved abnormal ,
-
From moved Exception to get the information of the target node .
-
6. The client sends commands to the target node , Get command execution result .
3、 ... and 、ASK to turn to
When the node needs to let the client only move to another node in the next command request , The node returns... To the client ASK
to turn to , Often occurs in data from the node A Migrate to node B When .
( come from : https://www.huaweicloud.com/articles/38e2316d01880fdbdd63d62aa26b31b4.html)
Execution process :
-
1. When a client sends a command to a node in the cluster ,
-
The node returns... To the client moved abnormal , Tell the client the node information of the corresponding target slot .
-
2. The client sends the command to the target node ,
-
The slot in the target node has been migrated to another node , At this point, the target node will return ask Redirect to client .
-
3. Client to new target The node sends Asking command ,
-
Then send the request command to the new node again .
-
4. New node target Carry out orders , Return the result of command execution to the client .
Example :
The slots listed in our previous section 8
In the case of , Because of the slot 8
The bonds contained are scattered in the nodes A And nodes B in , So when the client is at the node A When a key is not found in , It should turn to the node B In search of , But this shift should only affect one command query , Instead of having the client look up the node directly every time B : At the node A What is held belongs to the slot 8
There is no key for All moved to node B Before , The client should access the node first A , Then visit the node B .
Reference documents :
http://redisdoc.com/topic/cluster-spec.html
https://www.huaweicloud.com/articles/38e2316d01880fdbdd63d62aa26b31b4.html
边栏推荐
猜你喜欢
redis 集群模式原理
Cdga | six principles that data governance has to adhere to
[office] eight usages of if function in Excel
CDGA|数据治理不得不坚持的六个原则
COMSOL -- establishment of geometric model -- establishment of two-dimensional graphics
简单解决redis cluster中从节点读取不了数据(error) MOVED
COMSOL -- establishment of 3D graphics
【PyTorch预训练模型修改、增删特定层】
13. (map data) conversion between Baidu coordinate (bd09), national survey of China coordinate (Mars coordinate, gcj02), and WGS84 coordinate system
【上采样方式-OpenCV插值】
随机推荐
Mongodb replica set
[leetcode] wild card matching
基于Lucene3.5.0怎样从TokenStream获得Token
[singleshotmultiboxdetector (SSD, single step multi frame target detection)]
Programmers are involved and maintain industry competitiveness
Harbor image warehouse construction
2048 game logic
网络五连鞭
【pytorch 修改预训练模型:实测加载预训练模型与模型随机初始化差别不大】
What about SSL certificate errors? Solutions to common SSL certificate errors in browsers
Prevent browser backward operation
POJ 3176 cow bowling (DP | memory search)
[crawler] Charles unknown error
SET XACT_ABORT ON
Unity Xlua MonoProxy Mono代理类
vscode快捷键
【使用TensorRT通过ONNX部署Pytorch项目】
[mainstream nivida graphics card deep learning / reinforcement learning /ai computing power summary]
pytorch-softmax回归
项目总结笔记系列 wsTax KT Session2 代码分析