哈希相当于下面Python代码
{
"person":{
"name": "peigy",
"age": "18",
}
}
HSET添加哈希
127.0.0.1:6379> HSET website google "www.google.com"
(integer) 1
127.0.0.1:6379> HGET website google
"www.google.com"
删除哈希
127.0.0.1:6379> hdel website google
(integer) 1
获取所有的key value
127.0.0.1:6379> HSET website google "www.google.com"
(integer) 1
127.0.0.1:6379> HSET website baidu "www.baidu.com"
(integer) 1
127.0.0.1:6379> HGETall website
1) "google" #key
2) "www.google.com" #value
3) "baidu"
4) "www.baidu.com"
HMSET一次添加多个键值对
127.0.0.1:6379> HMSET person name xxx age 18 height 180
OK
127.0.0.1:6379> HGETall person
1) "name"
2) "xxx"
3) "age"
4) "18"
5) "height"
6) "180"
分别获取键值
127.0.0.1:6379> hkeys website
1) "google"
2) "baidu"
127.0.0.1:6379> hvals website
1) "www.google.com"
2) "www.baidu.com"
查看key是否存在
127.0.0.1:6379> HEXISTS website google
(integer) 1
127.0.0.1:6379> HEXISTS website sina
(integer) 0
获取总共的键值对
127.0.0.1:6379> HLEN website
(integer) 2
127.0.0.1:6379> HLEN person
(integer) 3
参考网站:http://redisdoc.com/hash/index.html