Redis Hash is a string-type field and value mapping table, and hash is particularly useful for storing objects.
Each hash in Redis can store 232-1 key-value pairs (more than 4 billion).
Instance
- Redis 127.0. 0.1:6379> hmset w3ckey name "Redis Tutorial" description "Redis basic commands for Cachin G " likes visitors 23000
- Ok
- Redis 127.0. 0.1:6379> hgetall w3ckey
- 1) "name"
- 2) "Redis tutorial"
- 3) "description"
- 4) "Redis basic commands for caching"
- 5) "likes"
- 6) " the"
- 7) "visitors"
- 8) "23000"
In the above example, we set up some of the Redis's descriptive information (name, description, likes, visitors) to the w3ckey of the hash table.
Redis Hash Command
The following table lists the basic related commands for Redis hashing:
Serial Number |
Command and Description |
1 |
Hdel key Field2 [Field2] Delete one or more hash table fields |
2 |
Hexists key field to see if the specified field exists in the hash table key. |
3 |
Hget key field gets the value stored in the specified field in the hash table/td> |
4 |
Hgetall key gets all fields and values that specify key in the hash table |
5 |
Hincrby key field increment adds an incremental increment to the integer value of the specified field in the hash table key. |
6 |
Hincrbyfloat key field increment adds an incremental increment to the floating-point value of the specified field in the hash table key. |
7 |
Hkeys key gets all the 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 given fields |
10 |
Hmset key field1 value1 [Field2 value2] simultaneously sets multiple field-value (domain-value) pairs to the hash table key. |
11 |
Hset key field value sets the values of the fields in the hash table key to be set to value. |
12 |
Hsetnx key field value sets the values of the hash table field only if the fields field does not exist. |
13 |
Hvals key gets all the values in the hash table |
14 |
The HSCAN key cursor [MATCH pattern] [count count] iterates over the key-value pairs in the hash table. |
Redis Hash (hash)