Redis集合相关命令

一、概要
redis中值可以是一个集合,集合的底层实现是INT_SET或HASH_TABLE。redis的集合命令包括往集合里添加、删除元素,对集合做差集、交集、并集操作。
二、代码示例

127.0.0.1:6379> HSET test a 1
(integer) 1
127.0.0.1:6379> HGET test a
"1"
127.0.0.1:6379> HSET test a 1
(integer) 1
127.0.0.1:6379> HSET test b 2
(integer) 1
127.0.0.1:6379> HGET test a
"1"
127.0.0.1:6379> HGET test c
(nil)
127.0.0.1:6379> HGETALL test
1) "a"
2) "1"
3) "b"
4) "2"
127.0.0.1:6379> HKEYS test
1) "a"
2) "b"
127.0.0.1:6379> HVALS test
1) "1"
2) "2"
127.0.0.1:6379> HINCRBY test b 10
(integer) 12
127.0.0.1:6379> HLEN test
(integer) 2
127.0.0.1:6379> HGET test b
"2"
127.0.0.1:6379> DEL test
(integer) 1
127.0.0.1:6379> HMSET test c 3 d 4 e 5
OK
127.0.0.1:6379> HGETALL test
 1) "a"
 2) "1"
 3) "b"
 4) "2"
 5) "c"
 6) "3"
 7) "d"
 8) "4"
 9) "e"
10) "5"
127.0.0.1:6379> HMGET test a b c e
1) "1"
2) "2"
3) "3"
4) "5"

猜你喜欢

转载自blog.csdn.net/gamekit/article/details/107593195