127.0.0.1:6379> SADD s1 a b c (integer) 3 127.0.0.1:6379> SMEMBERS s1 1) "b" 2) "c" 3) "a" 127.0.0.1:6379> SREM s1 a (integer) 1 127.0.0.1:6379> SCARD s1 (integer) 2 127.0.0.1:6379> SISMEMBER s1 a (integer) 0 127.0.0.1:6379> SISMEMBER s1 b (integer) 1 127.0.0.1:6379>
Set命令练习
将下列数据用Redis的Set集合来存储:张三的好友有:李四、王五、赵六李四的好友有:王五、麻子、二狗利用Set的命令实现下列功能
计算张三的好友有几人
计算张三和李四有哪些共同好友
查询哪些人是张三的好友却不是李四的好友
查询张三和李四的好友总共有哪些人
判断李四是否是张三的好友
判断张三是否是李四的好友
将李四从张三的好友列表中移除
127.0.0.1:6379> SADD zs lisi wangwu zhaoliu (integer) 3 127.0.0.1:6379> SADD ls wangwu mazi ergou (integer) 3 127.0.0.1:6379> SMEMBERS zs 1) "wangwu" 2) "lisi" 3) "zhaoliu" 127.0.0.1:6379> SCARD zs (integer) 3 127.0.0.1:6379> SINTER zs ls 1) "wangwu" 127.0.0.1:6379> SDIFF zs ls 1) "lisi" 2) "zhaoliu" 127.0.0.1:6379> SUNION zs ls 1) "lisi" 2) "wangwu" 3) "zhaoliu" 4) "ergou" 5) "mazi" 127.0.0.1:6379> SISMEMBER zs lisi (integer) 1 127.0.0.1:6379> SISMEMBER ls zs (integer) 0 127.0.0.1:6379> SREM zs lisi (integer) 1 127.0.0.1:6379>
标签:set,李四,0.1,数据类型,redis,6379,127.0,integer,zs From: https://www.cnblogs.com/ggborn-001/p/17082010.html