Ii. redis hash-type operations

Source: Internet
Author: User
Two types: hash type Introduction: redis

================================== Two types: hash type ========================== introduction: redis-hash is a string-type field-value ing table. hash is especially suitable for storing objects, compared with storing each field of an object into a single string type, storing an object in the hash type consumes less memory and can be easily accessed.

================================== Two types: hash type ============================
Description: redis-> hash is a string type field and value ing table.
Hash is especially suitable for storing objects. It stores each field of an object as a single string type.
Storing an object in the hash type consumes less memory and can easily access the entire object.


0: hset * If the key (that is, the hash table) does not exist, a new hash table is created and HSET is performed.
Set hash field to the specified value. If the key does not exist, create
Example: hset user: 001 name leyangjun creates a table

0.2: hsetnx
Set hash field to the specified value. If the value does not exist, create the value. If the value exists, 0 is returned.
Example: hsetnx user: 002 name leyangjun
1: hmset: Set the Field Values of multiple hash tables
Set multiple hash fields at the same time
Example: hmset user003 name leyangjun age 23 sex 1 --> hash table 003 value set successfully
Hget get: hget user: 003 name --> get the 003 name value of the hash table
2: hget
Obtains the specified hash field value.
Example: hget user003 name --> indicates the field
3: hmet
Obtains all specified hash fields.
Example: hmet user: 003 name age sex
4: hincrby)
Add a specified value to the specified hash field
Example: hincrby user: 003 age 5 --> Add 5 20 + 5 to the original age value
5: hexists
Test whether the specified field exists.
Example: hexists user: 003 sex --> judge whether the hash table field exists
6: hlen
Returns the number of all fields in the specified hash table.
Example: hlen user003
7: hdel
Deletes the field value in the specified hash table.
Example: hdel user003 age --> Delete the age field in user003
8: hkeys
Returns all fields in the hash table.
Example: hkeys user003
9: hvals
Returns all values of the hash table.
Example: hvals user003 --> values of keys in all tables
10: * Common hgetall
Obtains all fields and values in a hash.
Example: hgetall user003
========================================================== = END ============================================== =

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.