当前位置:网站首页>Execution of commands in the cluster

Execution of commands in the cluster

2022-06-26 15:00:00 Hua Weiyun

redis The execution of commands in the cluster

If the client sends key commands to the nodes in the cluster , Then you only need to assign the slot with the key to the current node for processing , If it is not on the current node , Return... To the client MOVED command . This command redirects the client to the correct node , Then send the command again . In cluster mode ,MOVED The command will hide

Calculation of the slot containing the database key

CRC 16 ( secret key ) % 16384 Calculate the slot to which the key belongs . among ,CRC16 ) key Statement is used to calculate the key key Of CRC16 The checksum . The cluster key slot key lets you see which slot this key is assigned to

Storage associated with the node and slot

How does the node determine whether the slot is in its own responsibility ? Obviously through the cluster state structure slots Array , If the cluster node indicated by the slot is in cluster status myself Property value , This node is responsible for , Otherwise, based on the indicated cluster node

Key and slot associated storage

The only way to save database key value pairs in a cluster is to use 0 The database . In addition to saving key value pairs in the database , Node also passes clusterState Medium slots_to_keys Jump table to save the direct relationship between key and slot . For each node score Is the slot number , Members are the keys of the database . Whenever a node adds a key value pair to the database , The key and slot Association will be added from the jump table , When deleting key value pairs , The key and slot Association will also be deleted from the jump table . The records in this jump table allow batch operation of all database keys in the slot .

summary

This is the execution process of commands in the cluster , Client sends command , If the command about the slot is executed at the current node , Return if it is not at the current node move command , Then redirect to the node responsible for this slot , Calculation database key The slot position of is based on key Of crc16 The value of is equal to 16384 modulus ,16384 yes redis All slots , Clustered slots The element of the array executes the current node, indicating that the slot is in the charge of this node .

️ Thank you for your

If you think this is helpful for you :

  1. Welcome to follow me ️, give the thumbs-up , Comment on , forward
  2. Focus on Panpan small class , Push good articles for you regularly , There are also group chat and irregular lottery activities , You can say what you want , Communicate with the great gods , Learning together .
  3. If there is anything inappropriate, you are welcome to criticize and correct .
原网站

版权声明
本文为[Hua Weiyun]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/177/202206261438086619.html