Introduction to five data types of redis

da0c061278e345fda9ac7fcda0a24b34.jpg, string (string)

 

 

It is the most basic type, which can be understood as the same type as Memcached, and a key corresponds to a value.

 

Note: A key can store up to 512MB.

 

Features: Can contain any data, such as jpg pictures or serialized objects, a key can store up to 512M

 

2. Hash

 

Redis hash is a collection of key-value (key=>value) pairs.

 

Redis hash is a mapping table of string type field and value, and hash is especially suitable for storing objects.

 

Note: Each hash can store 232 -1 key-value pairs (more than 4 billion).

 

Features: suitable for storing objects, and can only modify a certain attribute value like updating an attribute in the database (Memcached needs to take out the entire string and deserialize it into an object after modification and then serialize and store it back)

 

3. list (list)

 

Redis lists are simply lists of strings, sorted by insertion order. You can add an element to the head (left) or tail (right) of the list.

 

Note: Lists can store up to 232 - 1 elements (4294967295, each list can store more than 4 billion).

 

Features: Fast addition and deletion, providing an API for manipulating certain elements

 

4. set (collection)

 

Redis's Set is an unordered collection of string types.

 

The collection is implemented through a hash table, so the complexity of adding, deleting, and searching is O(1).

 

Note: In the above example, rabbitmq added twice, but according to the uniqueness of the elements in the collection, the second inserted element will be ignored.

 

The maximum number of members in a collection is 232 - 1 (4294967295, each collection can store more than 4 billion members).

 

characteristic:

 

1. The complexity of adding, deleting and searching is O(1)

 

2. Provides operations such as intersection, union, and difference for sets

 

5. sorted set: ordered collection

 

Redis zset, like set, is also a collection of string type elements, and duplicate members are not allowed.

 

The difference is that each element will be associated with a score of type double. Redis uses scores to sort the members of the set from small to large.

 

The members of zset are unique, but the score (score) can be repeated

Guess you like

Origin blog.csdn.net/weixin_57763462/article/details/132093929