Redis Hash
Redis hash is a map of string fields and string values, which is particularly suitable for storing objects.
Each hash in Redis can store up to 2^32 - 1 field-value pairs (more than 4 billion).
Example
127.0.0.1:6379> HMSET tutorialprokey name "redis tutorial" description "redis basic commands for caching" likes 20 visitors 23000
OK
127.0.0.1:6379> HGETALL tutorialprokey
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 descriptive information (name, description, likes, visitors) into the hash table tutorialprokey.
Redis Hash Commands
The table below lists the basic commands related to Redis hashes:
Number | Command and Description |
---|---|
1 | HDEL key field1 [field2] <br>Deletes one or more hash fields. |
2 | HEXISTS key field <br>Checks if a specified field exists in the hash. |
3 | HGET key field <br>Gets the value of a specified field in the hash. |
4 | HGETALL key <br>Gets all fields and values in the hash. |
5 | HINCRBY key field increment <br>Increments the integer value of a hash field by the given number. |
6 | HINCRBYFLOAT key field increment <br>Increments the float value of a hash field by the given number. |
7 | HKEYS key <br>Gets all the fields in the hash. |
8 | HLEN key <br>Gets the number of fields in the hash. |
9 | HMGET key field1 [field2] <br>Gets the values of all given fields. |
10 | HMSET key field1 value1 [field2 value2 ] <br>Sets multiple field-value pairs in the hash. |
11 | HSET key field value <br>Sets the value of a field in the hash. |
12 | HSETNX key field value <br>Sets the value of a hash field only if the field does not exist. |
13 | HVALS key <br>Gets all the values in the hash. |
14 | HSCAN key cursor [MATCH pattern] [COUNT count] <br>Iterates over the key-value pairs in the hash. |
For more commands, refer to: https://redis.io/commands