Hasehes
Redis Hash is a string-type field and value mapping table. Hash is particularly suitable for storing objects . Save as a string, you can now use less memory in a hash type. And it can be more convenient to store the entire object.
Hset
Redis 127.0.0.1:6379> hset user:001 name Michael
(integer) 1
Redis 127.0.0.1:6379> hget user:001 Name
"Michael"
Hsetnx
Redis 127.0.0.1:6379> hsetnx user:003 name Jason
(integer) 1
Redis 127.0.0.1:6379> hsetnx user:003 name Tom
(integer) 0-- set failed
Redis 127.0.0.1:6379> hget user:003 Name
"Jason" --value is not changed.
Hmset/hmget
Redis 127.0.0.1:6379> hmset user:004 name Michael age 1 Sex
Ok
Redis 127.0.0.1:6379> hget user:004 Name
"Michael"
Redis 127.0.0.1:6379> Hget user:004 Age
"29"
Redis 127.0.0.1:6379> hget user:004 Sex
"1"
Redis 127.0.0.1:6379> hmget user:004 name age sex
1) "Michael"
2) "29"
3) "1"
Hincrby
Redis 127.0.0.1:6379> Hincrby user:004 age 5
(integer) 34
Redis 127.0.0.1:6379> Hget user:004 Age
"34"
Hexists
Redis 127.0.0.1:6379> hexists user:004 Age
(integer) 1
Redis 127.0.0.1:6379> hexists user:004 Address
(integer) 0
Hlen
Redis 127.0.0.1:6379> Hlen user:004
(integer) 3
Hdel
Redis 127.0.0.1:6379> Hdel user:004 Age
(integer) 1
Redis 127.0.0.1:6379> hexists user:004 Address
(integer) 0
Redis 127.0.0.1:6379> Hget user:004 Age
(nil)
Hkeys hvals Hgetall
Redis 127.0.0.1:6379> Hkeys user:004
1) "Name"
2) "Sex"
Redis 127.0.0.1:6379> hvals user:004
1) "Michael"
2) "1"
Redis 127.0.0.1:6379> Hgetall user:004
1) "Name"
2) "Michael"
3) "Sex"
4) "1"
This article is from the "Software Design and Development" blog, please be sure to keep this source http://yuanzhitang.blog.51cto.com/2769219/1783356
[Redis Chapter4] Hash