redisTemplate的pipelined使用心得

首先是批量插入方法

redisTemplate.executePipelined(new SessionCallback<Object>() {
            @Override
            public Object execute(RedisOperations operations) throws DataAccessException {
                configInfos.stream().forEach(m -> {
                    operations.opsForValue().set(RedisConstants.alarm_config_key + m.getDeviceType() + ":" + m.getAlarmCategoryCode(), JSONObject.toJSONString(m));
                });
                //参数回调必须返回null,否则将抛出异常,可参考源码。
                return null;
            }
        });

然后是批量读取的时候,这里改了好几次,发现必须先全部读出来吗,然后在pipelined的外部进行处理操作,在里面进行操作不生效的。

List list = redisTemplate.executePipelined(
                new RedisCallback<String>() {
                    @Override
                    public String doInRedis(RedisConnection connection) throws DataAccessException {
                        for (String key : keys) {
                            connection.get(redisTemplate.getKeySerializer().serialize(key));
                        }
                        return null;
                    }
                }
        );

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值