Redis Hash
Redis hash is a mapping table of string type fields and values. Hash is particularly suitable for storing objects.
Each hash in Redis can store 232 - 1 key-value pairs (more than 4 billion).
Example
redis 127.0.0.1:6379> HMSET w3ckey name "redis tutorial" description "redis basic commands for caching" likes 20 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) "20" 7) "visitors" 8) "23000"
In the above example, we set some description information of redis (name, description, likes, visitors) to the w3ckey 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 field2 [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 Get the value of the specified field stored in the hash table. |
4 | HGETALL key Get all fields and values of the specified key in the hash table |
HINCRBY key field increment | Add increment to the integer value of the specified field in the hash table key. |
HINCRBYFLOAT key field increment | Add increment to the floating point value of the specified field in the hash table key. |
HKEYS key | Get all fields in the hash table |
HLEN key | Get the number of fields in the hash table |
HMGET key field1 [field2] | Get the values of all given fields |
HMSET key field1 value1 [field2 value2 ] | Set multiple field-value (field-value) pairs into the hash table key at the same time. |
HSET key field value | Set the value of field field in hash table key to value. |
HSETNX key field value | Set the value of the hash table field only when the field field does not exist. |
HVALS key | Get all values in the hash table |
HSCAN key cursor [MATCH pattern] [COUNT count] | Iterate over the key-value pairs in the hash table. |