Redis data types

Source: Internet
Author: User

Redis Data types

Redis supports five types of data: string (String), hash (hash), list, set (set), and Zset (sorted set: Ordered set).

String (String)

The string is the most basic type of redis, and a key corresponds to a value.

The string type is binary safe. This means that a Redis string can contain any data. For example, JPG images or serialized objects.

The string type is the most basic data type of Redis, and a key can store up to 512MB.

Instance:

In the above example we used Redis's SET and GET commands. The key is name and the corresponding value is Lixiao.

Note: a key can store up to 512MB.

Hash (hashed)

A Redis hash is a collection of key-value pairs.

Redis Hash is a string-type field and value mapping table, and hash is particularly useful for storing objects.

Instance:

The hash data type in the above example stores the user object that contains the user script information. In the example we used Redis Hmset, the Hgetall command, and theuser as the key value.

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

List (lists)

The Redis list is a simple list of strings, sorted by insertion order. You can add an element to the head of the list (to the left) or to the tail (to the right).

Instance:

The list can store up to 232-1 elements (4294967295, each of which can store more than 4 billion).

Set (SET)

Redis's set is an unordered collection of type string.

Sadd command

Adds a string element to the set set of key corresponding to successfully returning 1 if the element has returned in the collection 0,key the corresponding set does not have a return error.

Sadd Key Member
Instance:

Note: A has been added two times in the above example, but the second inserted element is ignored based on the uniqueness of the elements within the collection.

The maximum number of members in the collection is 232-1 (4294967295, each of which can store 40多亿个 members).

Zset (sorted set: Ordered set)

Redis Zset and set are also collections of string-type elements and do not allow duplicate members.

The difference is that each element is associated with a double-type fraction. Redis is a small-to-large ordering of the members in a collection by fractions.

Zset members are unique, but fractions (score) can be duplicated.

Zadd command

Adds an element to the collection, the element exists in the collection, and updates the corresponding score

Instance:

These are the five types of data for Redis.

Redis data types

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.