Redis Hash is a string-type field and value mapping table.
It's add, delete operations are O (1) (average), hash is particularly suitable for storing objects
Storing an object in a hash type always consumes less memory and makes it easier to access
The entire object.
Hset method: Sets the hash field to the specified value, and if key does not exist, first create
127.0.0.1:6379> hset user:001 Name Xiaoming
(integer) 1
127.0.0.1:6379> hget user:001 Name
"Xiaoming"
Hsetnx method: Sets the hash field to the specified value, and if key does not exist, it is created first.
Returns 0 if present.
127.0.0.1:6379> hsetnx user:001 name Xiaohong
(integer) 0
Hmset method: Batch Set hash field
127.0.01:6379> Get user:002 Name
(Error) ERR wrong number of arguments for ' get ' command
127.0.01:6379> hget user:002 Name
"Xiaoming"
127.0.01:6379> Hget user:002 Age
"10"
127.0.01:6379> Hget user:002 Gender
"1"
Hget method: Gets the value of the filed specified by the hash
Hmget method: Bulk Get hash specified filed value
127.0.01:6379> hmget user:002 Name Age gender
1) "Xiaoming"
2) "10"
3) "1"
Hincrby method: Specifies the hash field plus the specified value
127.0.01:6379> Hincrby user:002 age 8
(integer) 18
127.0.01:6379> hmget user:002 Name Age gender
1) "Xiaoming"
2) "18"
3) "1"
Hexists method: Test whether the specified field exists, existence returned 1
127.0.01:6379> hexists user:002 Name
(integer) 1
Hlen method: Returns the number of keys for the specified hash
127.0.01:6379> Hlen user:002
(integer) 3
Hdel method: Delete the filed of the specified hash
127.0.01:6379> Hdel user:002 Age
(integer) 1
127.0.01:6379> Hget user:002 Age
(nil)
Hkeys method: Returns all field of hash
127.0.01:6379> Hkeys user:002
1) "Name"
2) "Gender"
Hvals method: Returns all the value of a hash
127.0.01:6379> hvals user:002
1) "Xiaoming"
2) "1"
Hgetall method: Returns all fields and their corresponding values
127.0.01:6379> Hgetall user:002
1) "Name"
2) "Xiaoming"
3) "Gender"
4) "1"
Redis Data type: Hashes