A compressed list is one of the underlying implementations of the list key and hash keys.
The compression list is a sequential data structure composed of a series of specially coded contiguous blocks of memory, developed by Redis to conserve memory.
1, the composition of the compression list
2, the composition of the compressed list node
<1>previous_entry_length
The length of the previous node in the compressed list is recorded in bytes. can be 1 bytes or 5 bytes, the previous node is less than 254Byte can be saved with 1 bytes, the previous byte is greater than or equal to 254Byte can be saved with 5 bytes of its length. With this length, the compression list can be traversed from the beginning to the tail, or from the given pointer through the head or tail;
<2>encoding
Records the type and length of data held by the content property of a node, one byte, two bytes, five bytes long, the highest bit of the value 00, 01, and 10 for byte array encoding, and in addition to the highest bit record type, the length of the byte array is recorded by the remaining bits, and the highest bit of the value begins with 11. denotes integer encoding;
<3>content
Save the value of the node;
3. Chain Update
In order to satisfy the previous node, the current node is amplified, and finally the node size is updated for each node of the entire list, which is the chain update; the addition or deletion of nodes can cause cascading updates.
Causes of cascading updates:
<1> first of all, in the compression list there are just a number of contiguous, length between 250 bytes to 253 bytes of nodes, chain updates can occur, in practice, this situation is not much see;
<2> second, even if there is a chain update, but as long as the number of nodes updated, there will be no impact on performance;
Design and implementation of Redis