Reid操作list
3)列表类型list : linkedlist格式。支持重复元秦
lpush / rpush
lpop / rpop
案例:
@Test
public void test4(){
Jedis jedis = new Jedis("localhost", 6379);
// 操作
// 储存hash
jedis.lpush("mylist","a","b","c");
jedis.rpush("mylist","a","b","c");
// list 范围获取
List<String> mylist = jedis.lrange("mylist", 0, -1);
System.out.println(mylist);
// list 弹出
String lpop = jedis.lpop("mylist");
System.out.println(lpop);
String s = jedis.rpop("mylist");
System.out.println(s);
// list 范围获取
List<String> mylist2 = jedis.lrange("mylist", 0, -1);
System.out.println(mylist2);
// 关闭连接
jedis.close();
}
}
Jedis操作set&sorted
4)集合类型set:不允许重复元秦
sadd
smembers:获取所有元素
案例:
@Test
public void test5(){
//1. 获取连接
Jedis jedis = new Jedis();//如果使用空参构造,默认值 "localhost",6379端口
//2. 操作
// set 存储
jedis.sadd("myset","java","php","c++");
// set 获取
Set<String> myset = jedis.smembers("myset");
System.out.println(myset);
//3. 关闭连接
jedis.close();
}
标签:set,mylist,list,System,Reid,jedis,Jedis From: https://www.cnblogs.com/ssr1/p/16619825.html