May 16, 2021 Redis
Redis hash is a string type of field and value mapping table, hash is particularly suitable for storing objects.
Each hash in Redis can store 232 - 1 key pairs (more than 4 billion).
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 of the description information for redis (name, description, likes, visitors) into the w3ckey of the hash table.
The following table lists the basic commands for redis hash:
Serial number | Commands and descriptions |
---|---|
1 |
HDEL key field2 [field2]
Delete one or more hash table fields |
2 |
HEXISTS key field
See if 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 the fields and values that specify key in the hash table |
5 |
HINCRBY key field increment
Add incremental increments to the integer value of the specified field in the hash table key. |
6 |
HINCRBYFLOAT key field increment
Add increments to the floating-point value of the specified field in the hash table key. |
7 |
HKEYS key
Gets the fields in all hash tables |
8 |
HLEN key
Gets the number of fields in the hash table |
9 |
HMGET key field1 [field2]
Gets the values for 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 field in the hash table key to value. |
12 |
HSETNX key field value
Set the value of the hash table field only if 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 the key value pair in the hash table. |
For more commands, please refer to: http://redis.readthedocs.org/en/latest/index.html