Update documentation of transactions page.
Closes #2865 Original pull request: #2870
This commit is contained in:
committed by
Mark Paluch
parent
7e3986b8bd
commit
a4663d2a0b
@@ -25,6 +25,31 @@ System.out.println("Number of items added to set: " + txResults.get(0));
|
||||
`RedisTemplate` uses its value, hash key, and hash value serializers to deserialize all results of `exec` before returning.
|
||||
There is an additional `exec` method that lets you pass a custom serializer for transaction results.
|
||||
|
||||
It is worth mentioning that if between the commands multi() and exec() a query timeout exception happens (e.g. in case
|
||||
Redis is not available to respond fast) then the connection may get stuck in a transactional state. To prevent
|
||||
such situation you have to control the transaction state:
|
||||
|
||||
[source,java]
|
||||
----
|
||||
List<Object> txResults = redisOperations.execute(new SessionCallback<List<Object>>() {
|
||||
public List<Object> execute(RedisOperations operations) throws DataAccessException {
|
||||
boolean transactionStateIsActive = true;
|
||||
try {
|
||||
operations.multi();
|
||||
operations.opsForSet().add("key", "value1");
|
||||
|
||||
// This will contain the results of all operations in the transaction
|
||||
return operations.exec();
|
||||
} finally{
|
||||
if (transactionStateIsActive) {
|
||||
LOG.error("Transaction state is active");
|
||||
operations.discard();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
----
|
||||
|
||||
[[tx.spring]]
|
||||
== `@Transactional` Support
|
||||
|
||||
|
||||
Reference in New Issue
Block a user