Jedis操作set&Sortedset和Jedis连接池
集合类型 set:不允许重复元素
- sadd
- smembers:获取所有元素
@Test
public void MyTest04() {
Jedis jedis = new Jedis("localhost", 6379);
// long sadd = jedis.sadd("user", "zhangsan", "李四", "王五", "赵六", "田七");
// System.out.println(sadd);
System.out.println("移除前");
Set<String> user = jedis.smembers("user");
user.forEach(s -> {
System.out.println(s);
});
long srem = jedis.srem("user", "李四");
System.out.println("移除了--->" + srem);
System.out.println("移除后:");
Set<String> user1 = jedis.smembers("user");
user1.forEach(s -> {
System.out.println(s);
});
jedis.close();
}
有序集合类型sortedset:不允许有重复元素,且元素有顺序
存储:zadd key score value
获取:zrange key start end
删除:zrem key value
@Test
public void MyTest05() {
Jedis jedis = new Jedis("localhost", 6379);
// jedis.zadd("user", 1, "张三");
// jedis.zadd("user", 3, "李四");
// jedis.zadd("user", 2, "王五");
long zrem = jedis.zrem("user", "王五");
System.out.println(zrem);
List<String> user = jedis.zrange("user", 0, -1);
user.forEach(s -> System.out.println(s));
jedis.close();
}
}