@@ -25,9 +25,8 @@ 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:
|
||||
It is worth mentioning that in case between `multi()` and `exec()` an exception happens (e.g. a timeout exception in case Redis does not respond within the timeout) then the connection may get stuck in a transactional state.
|
||||
To prevent such a situation need have to discard the transactional state to clear the connection:
|
||||
|
||||
[source,java]
|
||||
----
|
||||
@@ -40,11 +39,9 @@ List<Object> txResults = redisOperations.execute(new SessionCallback<List<Object
|
||||
|
||||
// This will contain the results of all operations in the transaction
|
||||
return operations.exec();
|
||||
} finally{
|
||||
if (transactionStateIsActive) {
|
||||
LOG.error("Transaction state is active");
|
||||
} catch (RuntimeException e) {
|
||||
operations.discard();
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user