Redis hash (Hash)

Redis hash is a mapping table of field and value of string type, and hash is especially suitable for storing objects.

Each hash in Redis can store 232 - 1 key-value pairs (more than 4 billion).

example

127.0.0.1:6379>  HMSET runoobkey name "redis tutorial" description "redis basic commands for caching" likes 20 visitors 23000
OK
127.0.0.1:6379>  HGETALL runoobkey
1) "name"
2) "redis tutorial"
3) "description"
4) "redis basic commands for caching"
5) "likes"
6) "20"
7) "visitors"
8) "23000"

In the above example, we set some description information (name, description, likes, visitors) of redis to the runoobkey of the hash table.

Redis hash command

The following table lists the basic related commands of redis hash:

serial number Command and Description
1 HDEL key field1 [field2]
delete one or more hash table fields
2 HEXISTS key field
Check whether the specified field exists in the hash table key.
3 HGET key field
Gets the value of the specified field stored in the hash table.
4 HGETALL key
Gets all fields and values ​​of the specified key in the hash table
5 HINCRBY key field increment
is the integer value of the specified field in the hash table key plus increment increment.
6 HINCRBYFLOAT key field increment
is the floating point value of the specified field in the hash table key plus increment increment.
7 HKEYS key
to get all fields in the hash table
8 HLEN key
gets the number of fields in the hash table
9 HMGET key field1[field2]
Gets the values ​​of all the given fields
10 HMSET key field1 value1 [field2 value2 ]
Simultaneously sets multiple field-value (field-value) pairs into the hash table key.
11 HSET key field value
sets the value of the field field in the hash table key to value.
12 HSETNX key field value
sets the value of the hash table field only when the field field does not exist.
13 HVALS key
gets all the values ​​in the hash table
14 HSCAN key cursor [MATCH pattern] [COUNT count] Iterates over key
-value pairs in the hash table.

For more commands, please refer to: https://redis.io/commands

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325017845&siteId=291194637