RedisTemplate常用集合使用说明-boundListOps(八)

     基础配置介绍已经在前面的《RedisTemplate常用集合使用说明(一)》中已经介绍了,现在我们直接介绍boundListOps()方法的使用:

       首先要定义一个BoundListOperations

//定义绑定的键
BoundListOperations boundListOperations = redisTemplate.boundListOps("lk");

 1.leftPush(V value)和rightPush(V value)

     在绑定键中添加值

//在绑定的键中添加值
boundListOperations.leftPush("h");
boundListOperations.leftPush("i");
boundListOperations.rightPush("a");
boundListOperations.rightPush("b");

 2.range(long start, long end)

     获取绑定键中给定的区间值

//获取绑定的键中的值
boundListOperations.range(0,-1).forEach(v -> System.out.println("获取绑定的键中的值" + v));

3.index(long index)

    获取给定位置的值

 //获取特定位置的值
System.out.println("获取特定位置的值:" + boundListOperations.index(0));

 4.leftPop()

    弹出左边的值

//弹出左边的值
System.out.println("弹出左边的值:" + boundListOperations.leftPop());

5.rightPop()

    弹出右边的值

 //弹出右边的值
System.out.println("弹出右边的值:" + boundListOperations.rightPop());

6.leftPush(V pivot, V value)

    在指定的第一个值出现的左边添加值

//在指定的出现第一个值左边添加值
boundListOperations.leftPush("i","w");
boundListOperations.range(0,-1).forEach(v -> System.out.println("在指定的出现第一个值左边添加值:" + v));

7.rightPush(V pivot, V value)

    在指定的第一个值出现的右边添加值

//在指定的出现第一个值右边添加值
boundListOperations.rightPush("i","x");
boundListOperations.range(0,-1).forEach(v -> System.out.println("在指定的出现第一个值左边添加值:" + v));

8.leftPop(long timeout, TimeUnit unit)

    在指定的时间后弹出左边的值

//在指定的时间过后弹出左边的值
boundListOperations.leftPop(1, TimeUnit.SECONDS);

9.rightPop(long timeout, TimeUnit unit)

     在指定的时间后弹出右边的值

 //在指定的时间过后弹出右边的值
boundListOperations.rightPop(1, TimeUnit.SECONDS);

 10.leftPushAll(V... values)

     在左边批量添加值

//在左边批量添加值
boundListOperations.leftPushAll("y","g");
boundListOperations.range(0,-1).forEach(v -> System.out.println("在左边批量添加值:" + v));

11.rightPushAll(V... values)

    在右边批量添加值

//在右边批量添加值
boundListOperations.rightPushAll("b","r");
boundListOperations.range(0,-1).forEach(v -> System.out.println("在右边批量添加值:" + v));

12.leftPushIfPresent(V value)

      在左边添加不存在的值

//向左边添加不存在的值
boundListOperations.leftPushIfPresent("k");
boundListOperations.leftPushIfPresent(";");
boundListOperations.range(0,-1).forEach(v -> System.out.println("向左边添加不存在的值:" + v));

 13.rightPushIfPresent(V value)

     在右边添加不存在的值

//向右边添加不存在的值
boundListOperations.rightPushIfPresent("k");
boundListOperations.rightPushIfPresent(";");
System.out.println("向右边添加不存在的值:" + boundListOperations.range(0,-1).toString());

14.remove(long count, Object value)

    移除指定个数的值

//移除指定值的个数
long removeCount = boundListOperations.remove(2,"i");
System.out.println("移除指定值的个数:" + removeCount);
System.out.println("移除指定值的个数后剩余的值:" + boundListOperations.range(0,-1).toString());

15.set(long index, V value)

    在指定位置添加值

//在指定位置设置值
boundListOperations.set(0,"j");
System.out.println("在指定位置设置值:" + boundListOperations.range(0,-1).toString());

16.trim(long start, long end)

    截取原来区间的值为新值

//截取指定区间位置的值
boundListOperations.trim(1,3);
System.out.println("截取指定区间位置的值:" + boundListOperations.range(0,-1).toString());

 

 

 

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值