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