File tree 1 file changed +25
-0
lines changed
src/main/antora/modules/ROOT/pages/redis
1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,31 @@ System.out.println("Number of items added to set: " + txResults.get(0));
25
25
`RedisTemplate` uses its value, hash key, and hash value serializers to deserialize all results of `exec` before returning.
26
26
There is an additional `exec` method that lets you pass a custom serializer for transaction results.
27
27
28
+ It is worth mentioning that if between the commands multi() and exec() a query timeout exception happens (e.g. in case
29
+ Redis is not available to respond fast) then the connection may get stuck in a transactional state. To prevent
30
+ such situation you have to control the transaction state:
31
+
32
+ [source,java]
33
+ ----
34
+ List<Object> txResults = redisOperations.execute(new SessionCallback<List<Object>>() {
35
+ public List<Object> execute(RedisOperations operations) throws DataAccessException {
36
+ boolean transactionStateIsActive = true;
37
+ try {
38
+ operations.multi();
39
+ operations.opsForSet().add("key", "value1");
40
+
41
+ // This will contain the results of all operations in the transaction
42
+ return operations.exec();
43
+ } finally{
44
+ if (transactionStateIsActive) {
45
+ LOG.error("Transaction state is active");
46
+ operations.discard();
47
+ }
48
+ }
49
+ }
50
+ });
51
+ ----
52
+
28
53
[[tx.spring]]
29
54
== `@Transactional` Support
30
55
You can’t perform that action at this time.
0 commit comments