This is the seventh day of my participation in the August More text Challenge. For details, see:August is more challenging

List objects

1. Introduction to list objects

List objects can be encoded as ziplist or linkedList.

Ziplsit-encoded list objects use compressed lists as the underlying implementation, with each compressed list node holding one list element.

Ziplist-encoded list object

A linkedList-encoded list object uses a double-ended list as the underlying implementation, with each double-ended list node holding a string object, and each string object holding a list element.

The list object encoded by linkedList

2. List object encoding conversion

A list object uses ziplist encoding when it can satisfy both of the following conditions:

  • The list object holds all string elements less than 64 bytes in length;
  • List objects hold less than 512 elements; List objects that do not meet either of these criteria need to be encoded using linkedList.

However, the upper limits of the above two conditions can be changed. For details, see the description of list-max-ziplist-value and list-max-ziplist-entries options in the configuration file.

The following example shows a procedure for encoding a list object:

All elements are less than or equal to64Byte redis> RPUSH blah"hello" "world" "again"
(integer)3
redis> OBJECT ENCODING blah
"ziplist"Will a #65Byte long elements are pushed to list objects redis> RPUSH blah"wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww"
(integer)4Redis > OBJECT ENCODE blah"linkedlist"
Copy the code

Hash object

1. Hash object profile

The encoding of the hash object can be either ziplist or Hashtable.

The ziplist-encoded hash object uses the compressed list as the underlying implementation. Whenever a new key-value pair is added to the hash object, the program pushes the compressed list node holding the keys to the end of the compressed column table, and then pushes the compressed list node holding the values to the end of the compressed column table.

Ziplist-encoded hash object

The underlying implementation of a compressed list of hash objects

Hashtable-encoded hash objects use a dictionary as the underlying implementation, and each key-value pair in the hash object is held by a dictionary key-value pair: 1. Each key in the dictionary is a string object, and the object holds the key of the pair; 2. 2. Each value in the dictionary is a string object that holds the value of the key-value pair.

Hash object encoded by hashTable

2. Hash object encoding conversion

Hash objects use ziplist encoding when they can satisfy both of the following conditions:

  • The hash object holds all key-value pairs whose key and value strings are less than 64 bytes long;
  • The number of key-value pairs held by the hash object is less than 512; Hash objects that do not meet either of these conditions require hashtables encoding.

For details, see the hash-max-ziplist-value and hash-max-ziplist-entries options in the configuration file.