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