Introduction of 5 kinds of data types in Redis

Source: Internet
Author: User
Tags hash memcached redis set set


Redis and memcached Two kinds of caching, personally feel redis better use, because it not only provides a wealth of data types, but also to ensure the durability of the data, the following is a simple introduction to the Redis of several commonly used data types.

1. String type

This is the most basic type of redis, and the most commonly used type, like memcached, which is a key that corresponds to a value. Operation is also very simple, common operation commands have get, set, Del and so on.

2. Linked list type (list)

A linked list type is somewhat similar to an array in a programming language and can be stored in a set of data with a key. In fact, the list type is a two-way list, through the Lpush, Lpop, Rpush, rpop These four commands to the head of the linked list to insert, remove, tail insert, remove, which makes the list can be used as a stack, can also be used as a queue. The scenario shown in the following illustration:
Redis List Queue

3. Unordered collection type (set)

The set in Redis is a string-type unordered collection, and the set element can contain a maximum of 2 32-1 elements. With Set set type, we can quickly remove the combination of N key, intersection, difference set, and so on, so as to easily solve the MySQL database is not easy to achieve this operation of the defect. Application scene: Take out two QQ number in the common number of friends.

4. Ordered set type (sorted set)

As with set, sorted set is also a collection of string-type elements, a collection of strings that do not have duplicate elements. Because the elements are ordered, you can add, delete, and update elements with a very fast speed (O (log (N)), and it is also good at sorting. Application scenario: Gets the top 10 votes for all users, and so on.

5. Hash type (hash)

The data stored in the hash data type is very similar to storing a record in the MySQL database, which stores the mapping of field and field values, but the field values can only be strings and other types are not supported. Each hash can store more than 2 of the 32-1 field-value pairs. Scenario: Storing basic information about the user, and so on.

Conclusion: Only by mastering the characteristics of various data types, can the Redis be applied to the actual project. Although Redis efficiency is very high, but we still have a very clear understanding of each data type suitable for the application scenario, so that the Redis advantage to play to the extreme

Related Article

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.