Redis 4: storage type-Hash type

Source: Internet
Author: User
1. introduction to hash expression: ========================================================== ==== key field value =========================================== ========== front wheel ---> Foxconn rear wheel ---> Apple BMW: windscreen ---> jiadobao seat ---> Wang laoji steering wheel ---> Evergrande ice spring ==================== ======================== the hash type better applies to the same object, different attributes correspond to different values; for example, you cannot use the string type to achieve this result ================================== ==================== BMW: front Wheel ---> Foxconn BMW: Rear Wheel ---> Apple BMW: windshield ---> gabo BMW: Seat ---> Wang laoji BMW: steering wheel ---> Evergrande ice spring ======================================== ==========In this way, it is easy to cause unnecessary space waste and unnecessary increase of keys. assign hset to BMW front-wheel Foxconn 3. value: hget BMW front wheel. 3. batch assignment hmset BMW front wheel Foxconn rear wheel Apple 4. batch value: 5. obtain all the key value information hgetall6. determine whether the field exists hexists. If the front wheel of BMW, 1 is returned, and 07 is returned if no key value exists. determine whether the field exists. If it does not exist, assign a value to the hsetnx BMW seat Wang laoji. If "Seat" already exists, do not perform the operation. If "Seat" does not exist, set "Seat ", set the value of "Seat" to "Wang laoji" 8. add a number (if the number is reduced, set it to a negative number) hset BMW wheel count 3 // set the number of BMW wheels to 3 hincrby BMW wheel count 1 // Add one to the wheel, (The command will directly return the result after adding) 9. if the number of hdel BMW wheels is not needed that day, you can use hdel to delete it ====================================== ============= PS:: it can be seen that the hash type of redis is particularly useful for storing data with one-to-many relationships, because it means that you do not need to use strings to store these relationships, which greatly saves space and application complexity; ========================================================== ========
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.