当前位置:网站首页>Redis underlying data structure -- listpack

Redis underlying data structure -- listpack

2022-06-13 07:33:00 A hard-working dog

listpack Introduce

Redis stay 5.0 A new data structure called listpack, The purpose is to replace compressed lists , Its biggest feature is listpack Each node in no longer contains the length of the previous node , Each node in the compressed list needs to save the length field of the previous node , There will be a hidden danger of chain update .

listpack The structure design

listpack Many excellent designs with compressed lists , such as Or use a contiguous memory space to store data compactly , And to save memory overhead ,listpack Nodes use different encoding methods to save data of different sizes .

listpack  There are four parameters 
 Total bytes    Element quantity   Node node     End tag 

 Please add a picture description

listpack entry  The node structure 
encoding  Define the encoding type of the element , Will encode integers and strings of different lengths 
data  Data actually stored 
len,encoding+data The total length of 

 Please add a picture description
listpack There is no field in the compressed list to record the length of the previous node ,listpack Only record the length of the current node , When we turn to listpack When adding a new element , It will not affect the change of the length field of other nodes , Thus, the chain update problem of compressed list is avoided .

原网站

版权声明
本文为[A hard-working dog]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202270548049582.html