One, foreword

Redis provides five data types: String, Hash, List, Set, and Zset. Understanding the characteristics of each data type is important for the development and operation of Redis.

The original resolution

The list in Redis is a data type that we often use. It can be applied to many scenarios depending on how it is used.

Second, coding conversion

There are two ways to implement the List type of Redis:

1. List object implemented using ziplist. 2. List object implemented using linkedList

And that leaves the question, right? When is a Redis list ziplist encoded and when is a LinkedList encoded?

Referring to Redis Design and Implementation, a conclusion is drawn that there is a coding conversion mechanism between Ziplist and LinkedList. If the list object can meet the following two conditions at the same time, the list object adopts Ziplist encoding, otherwise, the linkedList encoding is adopted

(1) All string elements held by the list object are less than 64 bytes long;

(2) The number of stored elements in the list is less than 512;

Note: The upper limits of the above two conditions can be modified in the configuration file with the list-max-ziplist-value and list-max-ziplist-entries options. In addition, for ziplist-encoded list objects, if either of the above two conditions cannot be met, The encoding conversion of the object is performed, all the list elements that were stored in the ziplist are transferred to the double-ended list, and the encoding of the object is changed from ziplist to LinkedList.

Three, operation verification

The book is so said, but still want to verify their own operation, go!

Ziplist, LinkedList, and transcoding. What is this quickList structure? See this everybody may have a little meng force, fine after taste even want to start work: seven elder brother, your TM is not in cheat me?

Well, don’t worry about that. Listen to me beep beep.

Let’s take a look at the redis version of the operation:

./redis-server --version
Copy the code

Version display:

Look again, Huang Jianhong ** “Redis design and Implementation” ** in the second edition of the corresponding Redis version: 3.0, redis in version 3.2, considering the space storage efficiency and time efficiency of Redis, the introduction of quickList as the bottom implementation of list, originally so!

Quicklist 3.0 quickList 3.0 QuickList 3.0 QuickList 3.0 QuickList 3.0 QuickList 3.0

4. Summary of key points

(1) (before Redis 3.2 version) list object bottom implementation, ziplist (Ziplist) and double linkedList (linkedList) there is conversion

(2) (before Redis 3.2) both conditions are met: all string elements stored in the list object are less than 64 bytes in length; The list element holds less than 512 elements. List objects are ziplist encoded, otherwise linkedList encoded

(3) (Redis 3.2) Considering the space storage efficiency and time efficiency of Redis, QuickList is introduced as the bottom implementation of List

over