jedis操作set_Jedis 对 redis 的操作详解(下)

@Test public void testList()

{

jedis.flushDB();

System.out.println("===========添加一个list===========");

jedis.lpush("collections", "ArrayList", "Vector", "Stack", "HashMap", "WeakHashMap", "LinkedHashMap");

jedis.lpush("collections", "HashSet");

jedis.lpush("collections", "TreeSet");

jedis.lpush("collections", "TreeMap");

System.out.println("collections的内容:"+jedis.lrange("collections", 0, -1));//-1代表倒数第一个元素,-2代表倒数第二个元素

System.out.println("collections区间0-3的元素:"+jedis.lrange("collections",0,3));

System.out.println("===============================");

// 删除列表指定的值 ,第二个参数为删除的个数(有重复时),后add进去的值先被删,类似于出栈

System.out.println("删除指定元素个数:"+jedis.lrem("collections", 2, "HashMap"));

System.out.println("collections的内容:"+jedis.lrange("collections", 0, -1));

System.out.println("删除下表0-3区间之外的元素:"+jedis.ltrim("collections", 0, 3));

System.out.println("collections的内容:"+jedis.lrange("collections", 0, -1));

System.out.println("collections列表出栈(左端):"+jedis.lpop("collections"));

System.out.println("collections的内容:"+jedis.lrange("collections", 0, -1));

System.out.println("collections添加元素,从列表右端,与lpush相对应:"+jedis.rpush("collections", "EnumMap"));

System.out.println("collections的内容:"+jedis.lrange("collections", 0, -1));

System.out.println("collections列表出栈(右端):"+jedis.rpop("collections"));

System.out.println("collections的内容:"+jedis.lrange("collections", 0, -1));

System.out.println("修改collections指定下标1的内容:"+jedis.lset("collections", 1, "LinkedArrayList"));

System.out.println("collections的内容:"+jedis.lrange("collections", 0, -1));

System.out.println("===============================");

System.out.println("collections的长度:"+jedis.llen("collections"));

System.out.println("获取collections下标为2的元素:"+jedis.lindex("collections", 2));

System.out.println("===============================");

jedis.lpush("sortedList", "3","6","2","0","7","4");

System.out.println("sortedList排序前:"+jedis.lrange("sortedList", 0, -1));

System.out.println(jedis.sort("sortedList"));

System.out.println("sortedList排序后:"+jedis.lrange("sortedList", 0, -1));

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值