当前位置:网站首页>Redis transaction implements optimistic locking principle

Redis transaction implements optimistic locking principle

2022-04-23 07:59:00 Dream river dream

Transaction implementation

1)multi Pass before order watch Command monitor key;
2) perform multi command ;
3) The list of commands ;
4)exec Order to commit a transaction /discard Command rollback ;

watch Implementation principle of

1)redis Maintain a global watch_keys, Also a <key,value> structure ,key yes key+“&&”+ Connect id, It means that the client connection wants to listen to this key,value yes key Version number of , Every time you modify this key, Version number will be incremented .

2) When executed exec When ordered , Will execute every command in the transaction queue , When executing a write command , Will check the current key Does it exist in watch_keys in , If there is , It will check whether the version numbers of the two are equal , If equal, execute this write command , If they are not equal, no information is returned , Then delete watch_keys Corresponding to key;

版权声明
本文为[Dream river dream]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230629085697.html