RedisTemplate 事务处理方法 watch multi exec 的使用

时间:2019-09-11 14:00:37   收藏:0   阅读:714
    @Autowired
    RedisTemplate<String,String> redisTemplate;


        redisTemplate.execute(new SessionCallback<Object>(){

            @Override
            public <K, V> Object execute(RedisOperations<K, V> operations) throws DataAccessException {
                //开启事务
                operations.multi();
                for(int i = 1; i <= 5; i++) {
                    redisTemplate.convertAndSend("channel:test", String.format("我是消息{%d}号: %tT", i, new Date()));
                    redisTemplate.opsForValue().set("key" + i,"key" + i);
                }
                //执行事务
                operations.exec();
                return null;
            }
        });

 

原文:https://www.cnblogs.com/powerwu/p/11505716.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!