https://www.cnblogs.com/grey-wolf/p/10142937.html
https://docs.spring.io/spring-data/redis/docs/2.1.3.RELEASE/reference/html/#tx
使用以下这种方式不需要手动设置开启事务,否则报错
org.springframework.dao.InvalidDataAccessApiUsageException: ERR EXEC without MULTI;
nested exception is redis.clients.jedis.exceptions.JedisDataException:
ERR EXEC without MULTI
//execute a transaction
List<Object> txResults = redisTemplate.execute(new SessionCallback<List<Object>>() {
public List<Object> execute(RedisOperations operations) throws DataAccessException {
operations.multi();
operations.opsForSet().add("key", "value1");
// This will contain the results of all operations in the transaction
return operations.exec();
}
});
System.out.println("Number of items added to set: " + txResults.get(0));```