redis hash

Redis hash 是一个string类型的field和value的映射表,hash特别适合用于存储对象。
Redis 中每个 hash 可以存储 232 - 1 键值对(40多亿)。

1.设置
127.0.0.1:6379> hmset testhash a 1 b 2 c 3
OK

2.获取部分key的值
127.0.0.1:6379> hmget testhash a b
1) "1"
2) "2"

3.获取所有key
127.0.0.1:6379> hkeys testhash
1) "a"
2) "b"
3) "c"

4.获取所有值
127.0.0.1:6379> hvals testhash
1) "1"
2) "2"
3) "3"

5.获取所有key和值
127.0.0.1:6379> hgetall testhash
1) "a"
2) "1"
3) "b"
4) "2"
5) "c"
6) "3"

6.判断key是否存在,1存在 0不存在
127.0.0.1:6379> hexists testhash c
(integer) 1

7.删除key
127.0.0.1:6379> hdel testhash c
(integer) 1

猜你喜欢

转载自xiangjie88.iteye.com/blog/2346561