redis common data corresponding to the type of data structure

redis data types are achieved through a variety of data structures, mainly for reasons of time and space , when a small amount of data when accessed by the fastest array index, minimal amounts of memory [ compression list is a variant array, allowing different data sizes stored ]

Because the array needs to occupy contiguous memory space, so when a large amount of data when you need to use the list, and in order to ensure the speed they need and array combined, and will have a hash table.

1, string

2, a list (list): support storing a set of data , this data type corresponding to two methods, one is a compressed list , the other is a two-way circular linked list

Packing List : data set is relatively small when using compression list

A storage structure redis own design, similar to the array, by the data stored in a contiguous memory space, but it allows different data size storage

condition:

  • Individual data stored in the list is less than 64 bytes
  • List the number of data is less than 512

advantage:

  • Save memory
  • It supports different types of data storage
  • Data stored in a contiguous memory space, to obtain a list of types of data values ​​by the key, reading the efficiency is very high.
Two-way circular list : when a large amount of data, using a list of two-way circular linked list implementation
 
3, the dictionary (hash): storing a set of data , each data pair comprising a key and two parts.

Packing List : data set is relatively small when using compression list

condition:

  • List Save button value and size are less than 64 bytes
  • List of key-value pairs the number of less than 512

Hash table : the larger amount of data, the above condition is not satisfied, implemented using a hash table.

redis use MurmurHash2 this fast, good randomness of the hashing algorithm as a hash function for hash collision , redis use the list method to solve.

redis support the dynamic expansion of the hash table, felting.

4, a collection (set): one is based on an ordered array , one is based on a hash table .

Ordered arrays:

condition:

  • The stored data are integers
  • The number of data elements stored in no more than 512

Hash table:

5, ordered set (sort set):

For storing a set of data, and each data is provided with a score. By scoring the size, we will organize the data into a jump table such data structures to support the rapidly according to the scores, the score range of data acquisition.

Packing List : data set is relatively small when using compression list 

condition:

  • Stored data is less than 64 bytes
  • The number of elements is less than 128

Jump table:

 

Guess you like

Origin www.cnblogs.com/wjh123/p/11439705.html