3.1 redis five data types implementation principle

Description:

1. redis all data structures to a string as a unique key name, and then obtain the corresponding value through this unique key

2. The data structure of difference data of different types is that the value is not the same as the structure

1. string (string)

. 1 ) value data structure (array)

1. String value array-like data structure, easily employed to reduce the memory space allocated frequency allocation

2. When the string length is less than 1M, the expansion of existing space is doubled

3. If the length of the operating string 1M, 1M expansion expansion space at the most, the maximum length of the string 512M

2 ) use scenario string (buffer)

1. String a common use is to cache user information, we will use the information users JSON serialized into a String

Will go through a process of deserialization 2. user information fetch

List 2. (list)

. 1 ) value data structure (doubly linked lists)

1. Data Structure of the list is doubly linked list, which means that inserting and deleting time complexity is 0 (1) time complexity index of bit 0 (n)

2. When the pop-up list of the last element of the data structure will be automatically deleted, memory is counterassaulted

2 ) a list of usage scenarios (queues, stacks)

Hash 3. (dictionary)

. 1 ) value data structure (the HashMap)

1. redis The dictionary also HashMap (array + list) of two-dimensional structure

2. The difference is that the value of the dictionary can only be a string of redis

2 ) using the hash of the scene (buffer)

1. hash information can be used to cache the user, the string is different sequences all at once the entire object, hash can be stored separately for each field

2. This section acquires user information, save network traffic

3. hash also has disadvantages, storage consumption hash structure than a single string

Guess you like

Origin www.cnblogs.com/lihouqi/p/12664266.html