Redis Data Type

Source: Internet
Author: User
The translation string (Strings) of the official document of Redis is the most basic type of Redis value. Redis string is binary secure, which means that a Redis string can contain any type of data, such as a JPEG image or a serialized Ruby object. A string value can save up to MB of content. You

The translation string (Strings) of the official document of Redis is the most basic type of Redis value. Redis string is binary secure, which means that a Redis string can contain any type of data, such as a JPEG image or a serialized Ruby object. A string value can save up to MB of content. You

This article is a translation of the official Redis documentation.

String (Strings)

String is the most basic type of Redis value. Redis string is binary secure, which means that a Redis string can contain any type of data, such as a JPEG image or a serialized Ruby object. A string value can save up to MB of content. You can use the Redis string to do something interesting. For example, you can:

View available information for more information

List (Lists)

The Redis list is a simple string list sorted by insertion order. You can add a header (left) or tail (right) LPUSH command to insert a new element import header, while RPUSH inserts a new element import tail. when these two operations are executed on an empty Key, a new list is created. Similarly, if A List Operation clears a list, the corresponding key is deleted from the key space. This is very convenient syntax, because they are called to use an empty list, just like they are called to use a nonexistent key value (CAN) as a parameter. Examples of some table-like operations and results:

LPUSH mylist a # The current class table is ""

LPUSH mylist B # The current list is "B", ""

RPUSH mylist c # The current class table is "B", "a", "c" (This RPUSH is used)

A list can contain up to 232-1 elements (4294967295, each list contains more than 4 billion elements ). From the perspective of time complexity, the main feature of the Redis list is that the insertion and deletion of elements at the beginning and end are fixed at a fixed time, even millions of inserts .. The access element at both ends of the list is very fast, but if you try to access the element in the middle of a very large list, it is very slow because it is an O (N) operation. You can use the Redis list to do a lot of interesting things. For example, you can:

Sets)

The Redis Set is an unordered string Set. you can add, delete, and test the time complexity of O (1), regardless of the time complexity of all elements in the set. The Redis set has satisfactory attributes that cannot contain the same members. After adding the same element multiple times, only one element exists in the set. In fact, this means that when adding an element, you do not need to check whether the element exists. A very interesting thing about a Redis set is that it supports some server-side commands to perform set operations from the existing set, so you can merge (unions) in a very short time ), calculates the intersection to find different elements (differences of sets ). A set can contain a maximum of 232-1 elements (4294967295, each set contains more than 40 elements). You can use a set with many interesting things. For example, you can:

Hash (Hashes)

Redis Hashes is the ing between string fields and string values, so they are the perfect data type for displaying objects. (For example, a user with attributes such as name, surname, and age ):

@ Cli

HMSET user: 1000 username antirez password P1pp0 age 34

HGETALL user: 1000

HSET user: 1000 password 12345

HGETALL user: 1000

A hash with some fields (some here mean about one hundred) requires only a small space for storage, so you can store millions of objects in a small Redis instance. Hash is mainly used to represent objects and virtual hosts. They have the ability to store many objects, so you can use hash for many other tasks. Each hash can store over 232-1 field-value pairs (over 4 billion). View for more information.

Sorted Sets)

An ordered Redis set is very similar to a common set. It is a string set without repeated elements. The difference is that no member of an ordered set is associated with a score of the Hong Kong virtual host. This score is used to sort the members of the Set in the way from the lowest score to the highest score. The Set members are unique, but the scores can be repeated. You can use an ordered set to add, delete, and update elements at a very high speed (O (log (N. Because the elements are ordered, you can quickly obtain the elements in a range based on the score or position. The intermediate elements used to access an ordered set are also very fast. Therefore, you can use an ordered set as an intelligent list Without Duplicate members. In an ordered set, you can quickly access everything you need: ordered elements, quick existence tests, Hong Kong virtual hosts, and quick access to the intermediate elements of the set! In short, you can use an ordered set to complete many tasks that have extreme performance requirements. However, it is really difficult to use other types of databases for those tasks. You can use an ordered set:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.