Redis object and data structure

The key-value pairs of the Redis database are composed of objects.

There are 5 kinds of objects in total:

  1. String object (string)
  2. List object (list): an ordered linked list, value can be repeated, elements can be subscripted, and can be inserted or deleted at the head/tail. scenes to be used:
  3. Hash object (hash): HashMap
  4. Set object (set): non-repetitive, unordered, and elements that cannot be subscripted.
  5. Ordered collection object (zset)

The object is created by 6 main data structures :

  1. Simple dynamic string (SDS): Compared with C string, SDS has been optimized: directly obtain string reread, avoid buffer overflow, and pre-allocate space.
  2. Linked list: Double-ended non-ring linked list, which can quickly insert and delete elements at the head and end of the table, but the search complexity is high, and it is one of the underlying implementations of the list. No interface is provided to query whether an element exists in the linked list.
  3. Dictionary: Also known as: symbol table, associative array, mapping (map), the dictionary uses a hash table as the underlying implementation, using murmurhash for efficient hash calculation, linked list header interpolation to resolve hash conflicts, and progressive rehash to improve performance.
  4. Jump table: It is an ordered data structure, the efficiency is equivalent to that of a balanced tree, and it is simple to implement. It is constructed by layers. The bottom layer is an ordered linked list, and the upper layer is a fast query channel with varying heights, with layer heights ranging from 1 to 32.
  5. Integer set: the bottom layer is an ordered and non-repeating array. When the number of keys is less than 512 and the key value is an integer, the collection uses an integer collection as the bottom layer to save memory.
  6. Compressed list: When the list contains only a small number of small integers or short strings, the compressed list is used as the bottom layer to save memory.

 

 

Detailed analysis: https://blog.csdn.net/javahongxi/article/details/79500956

 

Guess you like

Origin blog.csdn.net/Anenan/article/details/115313249