Latest web development tutorials

Redis hash (Hash)

Redis hash is a string type of field and value mapping table, hash is particularly suitable for storing objects.

Redis can be stored for each hash 232--1 value pairs (4000000000).

Examples

127.0.0.1:6379>  HMSET w3bigkey name "redis tutorial" description "redis basic commands for caching" likes 20 visitors 23000
OK
127.0.0.1:6379>  HGETALL w3bigkey
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 redis some descriptive information (name, description, likes, visitors ) to the hash table w3bigkey.


Redis hash command

The following table lists the basic redis hash related commands:

No. Command and description
1 HDEL key field2 [field2]
Remove one or more fields hash table
2 HEXISTS key field
See the hash table key, the specified field exists.
3 HGET key field
Gets the value stored in the specified field in a hash table.
4 HGETALL key
Gets the key in the hash table all the fields and values
5 HINCRBY key field increment
An integer value in the hash table key fields plus the increment specified increment.
6 HINCRBYFLOAT key field increment
Hash table key field in the floating-point value plus the increment specified increment.
7 HKEYS key
Get 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 value of all the given field
10 HMSET key field1 value1 [field2 value2]
While the plurality of field-value (field - value) on the set to key in a hash table.
11 HSET key field value
The value of the hash table key fields in the field set to value.
12 HSETNX key field value
Only when the field field does not exist, set the value of the hash table fields.
13 HVALS key
Get all the values ​​in the hash table
14 HSCAN key cursor [MATCH pattern] [COUNT count]
Iterative hash table pairs.

For more commands, see: http://redis.readthedocs.org/en/latest/index.html