常用API之Set
public static void main(String[] args) { Jedis jedis = new Jedis("127.0.0.1",6379); jedis.auth("12345"); jedis.flushDB(); System.out.println("==================向集合中添加元素(不重复)=================="); System.out.println(jedis.sadd("eleSet","e1","e2","e3","e4","e5","e6","e7","e8")); System.out.println(jedis.sadd("eleSet","e9")); System.out.println("eleSet中所有元素为:"+jedis.smembers("eleSet")); System.out.println("删除一个元素e1:"+jedis.srem("eleSet","e1")); System.out.println("eleSet中所有元素为:"+jedis.smembers("eleSet")); System.out.println("随机移除集合中的一个元素:"+jedis.spop("eleSet")); System.out.println("随机移除集合中的一个元素:"+jedis.spop("eleSet")); System.out.println("eleSet中所有元素为:"+jedis.smembers("eleSet")); System.out.println("eleSet中包含元素的个数:"+jedis.scard("eleSet")); System.out.println("e3是否在eleSet中:"+ jedis.sismember("eleSet","e3")); System.out.println("e2是否在eleSet中:"+ jedis.sismember("eleSet","e2")); System.out.println("e9是否在eleSet中:"+ jedis.sismember("eleSet","e9")); System.out.println("============================================="); System.out.println(jedis.sadd("eleSet1","e1","e2","e3","e4","e5","e6","e7","e8")); System.out.println(jedis.sadd("eleSet2","e0","e9","e3","e4","e5")); System.out.println("将eleSet1中删除e1并存入eleSet3中:"+jedis.smove("eleSet1","eleSet3","e1")); System.out.println("将eleSet1中删除e3并存入eleSet3中:"+jedis.smove("eleSet1","eleSet3","e3")); System.out.println("eleSet1中所有元素为:"+jedis.smembers("eleSet1")); System.out.println("eleSet3中所有元素为:"+jedis.smembers("eleSet3")); System.out.println("========================集合运算====================="); System.out.println("eleSet1中的元素:"+jedis.smembers("eleSet1")); System.out.println("eleSet2中的元素:"+jedis.smembers("eleSet2")); System.out.println("eleSet1和eleSet2的交集:"+jedis.sinter("eleSet1","eleSet2")); System.out.println("eleSet1和eleSet2的并集:"+jedis.sunion("eleSet1","eleSet2")); System.out.println("eleSet1和eleSet2的差集:"+jedis.sdiff("eleSet1","eleSet2")); System.out.println(jedis.sinterstore("eleSet4","eleSet1","eleSet2")); System.out.println("eleSet4中的元素:"+jedis.smembers("eleSet4")); }