Description of hash types in Redis

Source: Internet
Author: User
Tags hash redis mysql database

In Redis, the hash data type stores data in a very similar way to storing a record in a MySQL database, a string-type field and value mapping table, which is particularly well-suited for storing objects, but the field values can only be strings and no other types are supported.


In the hash type, a key can correspond to more than one field, and a field corresponds to a value. One of the benefits of storing an object as a hash type is that it can save memory more than if each field is stored separately as a string type.


Here is a hash (hash) Type of common Operations Command:


1. "Hset key field value" Sets the hash field to the specified value, and if key does not exist, it is created first.

2. "Hmset key field1 value1 ... fieldn valuen" sets multiple values at the same time.

3. "Hget key field" Gets the specified hash field

4. "Hmget key field1 field1 ... fieldn" gets the specified multiple hash field

5. "Hincrby key field num" adds the specified hash field to the specified value.

6. "Hexists key field" To see if the specified field exists.

7. "Hdel key Field" Deletes the specified hash field.

8. "Hlen Key" returns the number of field in the specified hash.

9. "Hkeys key" returns the hash of all field.

10. "Hvals" returns all the value in the hash.

11. "Hgetall Key" returns all field and value in the hash.


Each hash can store more than 2 of 32 square-1 field-value pairs. Application scenario: can be used to store the user's basic information, and so on.

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.