Skip to content

Update documentation of transactions page #2870

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/main/antora/modules/ROOT/pages/redis/transactions.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down