data structure:
Hash, compared with the data structure of Map, the K and V modes remain unchanged, and V is a key-value pair.
Hash commonly used commands:
HSET / HGET : create/get a key-value pair
115.159.67.200:6379[1]> HSET user id 1001
(integer) 1
115.159.67.200:6379[1]> HGET user id
"1001"
HMSET / HMGET : Create/get multiple attributes and values for the key at once
115.159.67.200:6379[1]> HMSET user gender man age 20
OK
115.159.67.200:6379[1]> HMGET user
115.159.67.200:6379[1]> HMGET user id gender age
1) "1001"
2) "man"
3) "20"
HGETALL : Get all the attributes and values of the key
115.159.67.200:6379[1]> HGETALL user
1) "id"
2) "1001"
3) "gender"
4) "man"
5) "age"
6) "20"
HDEL : delete an attribute of key
115.159.67.200:6379[1]> HDEL user gender
(integer) 1
115.159.67.200:6379[1]> HGETALL user
1) "id"
2) "1001"
3) "age"
4) "20"
HLEN : Get the number of key attributes
115.159.67.200:6379[1]> HLEN user
(integer) 2
HEXISTS : Query whether there is an attribute in the key, it returns 1, otherwise it returns 0
115.159.67.200:6379[1]> HEXISTS user id
(integer) 1
115.159.67.200:6379[1]> HEXISTS user name
(integer) 0
HKEYS / HVALS : query
115.159.67.200:6379[1]> HKEYS user
1) "id"
2) "age"
115.159.67.200:6379[1]> HVALS user
1) "1001"
2) "20"
HINCRBY / HINCRBYFLOAT : Add a specified value to a numeric attribute value
115.159.67.200:6379[1]> HINCRBY user age 2
(integer) 22
115.159.67.200:6379[1]> HINCRBY user age 2
(integer) 24
115.159.67.200:6379[1]> HSET user score 99.5
(integer) 1
115.159.67.200:6379[1]> HINCRBYFLOAT user score 0.5
"100"
HSETNX : set is not exsist creates an attribute that does not exist yet, if the attribute already exists, the creation fails
115.159.67.200:6379[1]> HSETNX user id 111
(integer) 0
115.159.67.200:6379[1]> HSETNX user name zs
(integer) 1
115.159.67.200:6379[1]> HKEYS user
1) "id"
2) "age"
3) "score"
4) "name"