Redis Hash (hash)
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
127.0.0.1:6379>Hmset Runoobkey Name"Redis Tutorial"Description"Redis basic commands for caching"Likes20Visitors23000Ok127.0.0.1:6379>Hgetall Runoobkey1) "Name"2) "Redis Tutorial" Span class= "PLN" >3) "description" 4) "Redis basic commands for Caching "5) " likes " Span class= "PLN" >6) "20" 7) "visitors" 8) "23000"
In the above example, we set up some of the Redis's descriptive information (name, description, likes, visitors) to the Runoobkey 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 Look at the hash table key, the specified field exists. |
3 |
Hget key Field Gets the value that is stored in the specified field in the hash table. |
4 |
Hgetall Key Get 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 the fields from all the hash tables |
8 |
Hlen Key Gets the number of fields in the hash table |
9 |
Hmget key field1 [Field2] Gets the value of all given fields |
10 |
Hmset key field1 value1 [Field2 value2] Set multiple Field-value (domain-value) pairs to the hash table key at the same time. |
11 |
Hset key field value Set the value of the field in the hash table key to values. |
12 |
Hsetnx key field value Sets the value of the hash table field only if the field does not exist. |
13 |
Hvals Key Get all values in the hash table |
14 |
HSCAN key cursor [MATCH pattern] [count Count] Iterates over key-value pairs in a hash table. |
Redis Hash (hash)