You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
return hashCommands.hexists(key, "field"); // Produce a result (boolean in this case)
803
805
},
804
-
(exists, tx) -> { // The transactional block, receives the result and the transactional data source
805
-
if (exists) {
806
-
tx.hash(String.class).hset(key, "field", "new value");
807
-
} else {
808
-
tx.discard();
809
-
}
810
-
},
811
-
key); // The watched key
806
+
(exists, tx) -> {
807
+
// The transactional block, receives the result and the transactional data source
808
+
if (exists) {
809
+
tx.hash(String.class).hset(key, "field", "new value");
810
+
} else {
811
+
tx.discard();
812
+
}
813
+
},
814
+
// The watched key
815
+
key);
812
816
----
813
817
814
818
If one of the watched keys is touched before or during the execution of the pre-transaction or transactional blocks, the transaction is aborted.
@@ -821,9 +825,35 @@ Consequently, the pre-transaction block must use the passed data source to execu
821
825
Thus, the commands are emitted from that connection.
822
826
These commands must not modify the watched keys.
823
827
824
-
The transaction is aborted if the pre-transaction block throws an exception (or produces a failure when using the reactive API).
828
+
==== Error handling
829
+
830
+
If the transaction block returns successfully (or completes with an item in case of the reactive API), the transaction is executed.
831
+
Note that in this case, some transaction commands may succeed and some may fail; this is standard Redis behavior.
832
+
The `TransactionResult.hasErrors()` method indicates whether at least one command failed.
833
+
Results of failed commands in the `TransactionResult` are represented as ``Throwable``s.
834
+
If the transaction block throws an exception (or completes with a failure in case of the reactive API), the transaction is discarded automatically and the exception is rethrown (or the resulting `Uni` completes with the same failure in case of the reactive API).
835
+
836
+
In case of the optimistic locking API, if the pre-transaction block returns successfully (or completes with an item in case of the reactive API), the transaction is started and execution proceeds to the transaction block.
837
+
If the pre-transaction block throws an exception (or completes with a failure in case of the reactive API), all watched keys are ``UNWATCH``ed automatically and the exception is rethrown (or the resulting `Uni` completes with the same failure in case of the reactive API).
838
+
In this case, the transaction is not started and the transaction block is not executed.
839
+
840
+
==== Transactions in Redis Cluster
841
+
842
+
In the cluster mode, transaction commands (`MULTI`, `EXEC`, `DISCARD`, `WATCH`, `UNWATCH`) are handled specially.
843
+
844
+
By default, transactions in cluster are disabled and transaction commands immediately fail.
845
+
846
+
It is however possible to enable single-node transactions by setting `quarkus.redis.cluster-transactions` to `single-node`.
847
+
Note that this setting only makes sense in the cluster mode and is ignored otherwise.
848
+
849
+
In this mode, the `MULTI` command is queued and is only issued when the next command is executed.
850
+
This next command binds the connection to the corresponding node of the Redis cluster (so it should have keys, otherwise the target node is random).
851
+
All subsequent commands are targeted to that node.
852
+
If some of the subsequent commands have a key that belongs to another node, the command fails on the server side.
853
+
If `WATCH` is used before `MULTI`, its key(s) determine to which node the connection is bound and the subsequent `MULTI` is not queued.
854
+
If `WATCH` keys belong to multiple nodes, the command fails on the client side.
825
855
826
-
==== Execute custom commands
856
+
=== Execute custom commands
827
857
828
858
To execute a custom command, or a command not supported by the API, use the following approach:
829
859
@@ -927,8 +957,8 @@ The documentation of the Vert.x Redis Client is available on the https://vertx.i
927
957
928
958
== Configure Redis hosts programmatically
929
959
930
-
The `RedisHostsProvider` programmatically provides redis hosts.
931
-
This allows for configuration of properties like redis connection password coming from other sources.
960
+
The `RedisHostsProvider` programmatically provides Redis hosts.
961
+
This allows for configuration of properties like Redis connection password coming from other sources.
0 commit comments