Five types of REDIS data type---hash type

Source: Internet
Author: User
Tags hash redis
Introduction

Common commands: Hget;hset;hgetall, etc.

We can consider the hashes type in Redis as a map container with string key and string value. Therefore, this type is ideal for storing information about value objects. such as username, password, and age. If a hash contains very few fields, the data of that type will take up only a small amount of disk space. Each hash can store 4,294,967,295 key-value pairs.
Application Scenarios

Also, in memcached, we often package structured information into HashMap, which is stored as a string value after the client is serialized, such as the user's nickname, age, gender, integral, and so on, when one of the items needs to be modified, and when all of the values are taken out of deserialization, Modify the value of an item, and then serialize the store back. This not only increases the overhead, but also does not apply to some scenarios where concurrent operations are possible (for example, two concurrent operations need to modify the integral). The hash structure of Redis allows you to modify only one item property value just as you would update a property in a database.
Example Introduction

Key value

UserID Username;age;birthday

Normal storage mode:

The first kind: Key:userid; value:username;age;birthday

The second type: Key:userid+name value:name

Key:userid+age Value:age

Key:userid+birthday Value:birthday;

The first drawback: when you need to modify one of the items, such as birthdays, you need to take the whole object out, update the value, and then put it in. At the same time, in the modification also to protect concurrency, to avoid the production of dirty data, etc.;

The second disadvantage: The user ID has been repeatedly stored, wasting memory;

If you use a Redis hash type, it will be stored like this, as shown below:

Key is still a userid, but the value is a map,map still exists key and Value;key is the name tag, the corresponding value is the specific name, if you need to modify the name value, only add Userid+field (name) can modify the name value. This operation does not require the data to be stored repeatedly, nor does it need to worry about the first, and then the concurrency is taken out. list of related commands

Here are just a few common


(Each of the articles on Redis here is a first draft, because the small part is still in the study, will be constantly updated)

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.