Hash

Similar to the Map > < K, V

Create values and delete

The title
hset Set the value of field in the hash table to value. If the given hash table does not exist, a new hash table is created and the HSET operation is performed. If the field already exists in the hash table, its old value will be overwritten by the new value value.
hget Returns the value of the given field in the hash table.
hgetall Return all fields and values in the hash table key. In the return value, each field name is followed by the value of the field, so the length of the return value is twice the size of the hash table.
hmget Returns the value of one or more fields in the hash table key. Returns nil if the given field does not exist in the hash table. Because a nonexistent key is treated as an empty hash table, an HMGET operation on a nonexistent key returns a table with nil values only.
hdel Removes one or more specified fields from the hash table key. Non-existing fields are ignored.
127.0.0.1:6379> hset myhash k1 v1 k2 v2 k3 v3 k4 v4   Create the same as hmset
(integer) 4
127.0.0.1:6379> hget myhash k3               Get the Value of the Key (field) in the hash
"v3"127.0.0.1:6379 > hgetall myhashGet all K (field) -v of hash
1) "k1"      # key (field)
2) "v1"      # value
3) "k2"
4) "v2"
5) "k3"
6) "v3"
7) "k4"
8) "v4"
127.0.0.1:6379> hmget myhash k2 k4    Get the value of multiple keys (fields) in the hash
1) "v2"
2) "v4"127.0.0.1:6379 > hdel myhash k3# Remove key (field) and value from hash
(integer) 1
127.0.0.1:6379> hgetall myhash
1) "k1"
2) "v1"
3) "k2"
4) "v2"   
5) "k4"
6) "v4"
Copy the code

Find the size to see if it exists

The title
hlen Returns the number of fields in the hash table key.
hexists Checks whether the given field exists in the hash table. Return value: The HEXISTS command returns 1 if the given field exists and 0 if the given field does not exist.
hkeys Returns all fields in the hash table key.
hvals Returns the values of all fields in the hash table key.
127.0.0.1:6379 > hgetall myhash 1)"k1"
2) "v1"
3) "k2"
4) "v2"
5) "k4"
6) "v4"127.0.0.1:6379 > hlen myhash (integer) 3
127.0.0.1:6379> hexists myhash k4  # Check whether k4 exists
(integer1)# there
127.0.0.1:6379> hexists myhash k3
(integer) 0                         # there is no127.0.0.1:6379 > hkeys myhash# take key
1) "k1"
2) "k2"
3) "k4"127.0.0.1:6379 > hvals myhash# take value
1) "v1"
2) "v2"
3) "v4"
Copy the code