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


    @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;
            }
        });

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM