Redis has strings, HASHS, lists, sets, sorted sets five kinds of data types, can be said to be more rich. The following is a brief introduction to the data structure and use of these data types. As for each data type of Operation API, here is only a simple mention, no longer one by one detailed introduction, the need for users can Google.
First, Strings
The string is the simplest type, and a key corresponds to a value. The string type is type-safe, and a Redis string can contain any data, such as a JPG image or a serialized object. The storage structure is as follows:
The commonly used API functions are:
second, lists (stack/queue)
List is a linked list structure, the main function is Push/pop, get all the values of a range and so on. The key in the operation is understood as the name of the linked list. The list type of Redis is actually a doubly linked list where each child element is a string type. We can add and remove elements from the head or tail of the list by push, pop operations, so that the list can do both the stack and the queue. The storage structure is as follows:
The commonly used API functions are:
Third, Hashs
The Redis hash is a string-type field and value mapping table. Of the five data types, only the hash is two-dimensional, which is particularly suitable for storing objects. Each field property of an object is compared to a single string type. Storing an object in a hash type consumes less memory and makes it easier to access the entire object. The storage structure is as follows:
The commonly used API functions are:
Iv. Sets
Sets is a collection, which is an unordered collection of type string. Set is implemented by hash table. It is very similar to the set in mathematics, so we can take the combination, the difference set, the intersection. Through these actions we can realize the friend recommendation in SNS and the tag function in the blog. The storage structure is as follows:
The commonly used API functions are:
Wu, sorted sets
Sortedsets is an upgraded version of sets, which adds a sequential attribute score based on sets. This property can be specified when adding or modifying elements, and Zset automatically re-adjusts the order of the new values after each assignment. It can be understood that there are two columns of MySQL table, one column in value, and one in the order of storage. Key in operation is understood as the name of Zset. The storage structure is as follows:
The commonly used API functions are:
Five types of data have been introduced, and the following are the common key-value commands and server commands:
vi. Key-value related commands
VII. Server-related commands
eight or five data types storage structure Panorama
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
redis--Five types of data