Update documentation of transactions page.

Closes #2865
Original pull request: #2870
This commit is contained in:
Egor Ponomarev
2024-03-13 10:45:24 -05:00
committed by Mark Paluch
parent bfb46e0a8f
commit 4cf08c7c22

View File

@@ -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