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)