Redis Hash is a mapping table of field and value of string type. Hash is especially suitable for storing objects.
Note: Each hash in Redis can store 232 - 1 key-value pairs (more than 4 billion).
For example this:
Note: Here, we first recommend a redis visualization tool https://redisdesktop.com/download , which is very helpful for redis learning and daily operation
1 Assign a value to a field in the hash table (single assignment) [HSET KEY_NAME FIELD VALUE]
Note:
If the hash table does not exist, a new hash table is created and an HSET operation is performed.
If the field already exists in the hash table, the old value will be overwritten.
2. Set multiple hash key values at the same time [hmset key field1 "value1" field2 "value2"]
Three delete one or more specified fields in the hash table key [HDEL KEY FIELD1.. FIELDN]
Note: fields that do not exist will be ignored
Four Check whether the specified field of the hash table exists [HEXISTS KEY FIELD_NAME ]
5 Get the value of the specified field in the hash table [HGET KEY_NAME FIELD_NAME]
Six Get all fields in Hash table [HKEYS key]
Seven Get the number of fields in the hash table [HLEN KEY_NAME]
8. Get the value of one or more given fields in the hash table (corresponding to HMSET) [HMGET KEY_NAME FIELD1...FIELDN]
9 Assign values to fields that do not exist in the hash table (corresponding to HSET) [ HSETNX KEY_NAME FIELD VALUE ]
Note: If the setting is successful, return 1. Returns 0 if the given field already exists and no operation was performed