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

 

相关文章:

  • 2021-09-09
  • 2021-07-06
  • 2022-01-11
  • 2022-12-23
  • 2022-12-23
  • 2021-11-24
  • 2021-09-04
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-22
  • 2021-11-14
  • 2021-08-14
  • 2021-04-22
  • 2021-11-30
  • 2021-08-26
相关资源
相似解决方案