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 ============================================== =