Type and operation of a hashes
Redis Hash is a string-type field and value mapping table. It's added, the delete operation is 0 (1) (average). Hash is particularly suitable for storing objects, compared to Gencun each word of an object into a single string type. Storing an object in a hash type consumes less memory and makes it easier to access the entire object.
1 Hset
Sets the hash field to the specified value, and if key does not exist, it is created first.
Redis 127.0.0.1:6379> hset user:001 name Lisi
(integer) 0
Redis 127.0.0.1:6379> hget user:001 Name
"Lisi"
2.hsetnx
Sets the hash field to the specified value, and if key does not exist, it is created first. Returns 0 if present.
127.0. 0.1:6379> Hsetnx User:0010127.0. 0.1:6379> Hget User:001 name"Lisi"
3,hmset
Multiple field with hash set
Redis127.0.0.1:6379>hmset myhash field1 Hello field2 worldokredis127.0.0.1:6379>hget myhash field1"Hello"Redis127.0.0.1:6379>hget Myhash field2" World"Redis127.0.0.1:6379>
4 Hget
Gets the specified hash field
5. Hmget
Gets all the specified hash field
Redis127.0.0.1:6379>hmset myhash field1 Hello field2 worldokredis127.0.0.1:6379>hget myhash field1"Hello"Redis127.0.0.1:6379>hget Myhash field2" World"Redis127.0.0.1:6379>hmget myhash field1 field21)"Hello"2)" World"
6. Hincrby
Specifies the hash field plus the given value.
Redis127.0.0.1:6379> Hset Myhash Age1(integer)1Redis127.0.0.1:6379>hget Myhash Age"1"Redis127.0.0.1:6379> Hincrby Myhash Age8(integer)9Redis127.0.0.1:6379>hget Myhash Age"9"
7. hexists
Tests whether the specified field exists.
127.0. 0.1:6379>1
8 Hlen
Returns the number of field for the specified hash
127.0. 0.1:6379>3
9. Hdel
Delete field with specified hash
127.0. 0.1:6379>1
Ten. Hkeys
Return hash of all field
127.0. 0.1:6379> hkeys myhash1"field2"2" Age"
Hgetall.
Gets all the field and value in a hash.
127.0. 0.1:6379> hgetall myhash1"field2"2 " World " 3 " Age " 4 " 9 "
Redis03 using Redis Database (hashes type)