forked from valkey-io/valkey-glide
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Java: Add `WATCH` and `UNWATCH` command * Addressed PR comments * Added unwatch with route and improved tests * Fixed test based on submodule changes * Addressed PR comments * Added example for watch returning null * Added crossSlot test * Addressed comments * Commented out a test due to a bug * Address PR comments
- Loading branch information
Showing
11 changed files
with
381 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
java/client/src/main/java/glide/api/commands/TransactionsBaseCommands.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0 */ | ||
package glide.api.commands; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
|
||
/** | ||
* Supports commands for the "Transactions Commands" group for standalone and cluster clients. | ||
* | ||
* @see <a href="https://redis.io/commands/?group=transactions">Transactions Commands</a> | ||
*/ | ||
public interface TransactionsBaseCommands { | ||
/** | ||
* Marks the given keys to be watched for conditional execution of a transaction. Transactions | ||
* will only execute commands if the watched keys are not modified before execution of the | ||
* transaction. | ||
* | ||
* @apiNote When in cluster mode, the command may route to multiple nodes when <code>keys</code> | ||
* map to different hash slots. | ||
* @see <a href="https://redis.io/docs/latest/commands/watch/">redis.io</a> for details. | ||
* @param keys The keys to watch. | ||
* @return <code>OK</code>. | ||
* @example | ||
* <pre>{@code | ||
* assert client.watch(new String[] {"sampleKey"}).get().equals("OK"); | ||
* transaction.set("sampleKey", "foobar"); | ||
* Object[] result = client.exec(transaction).get(); | ||
* assert result != null; // Executes successfully and keys are unwatched. | ||
* | ||
* assert client.watch(new String[] {"sampleKey"}).get().equals("OK"); | ||
* transaction.set("sampleKey", "foobar"); | ||
* assert client.set("sampleKey", "hello world").get().equals("OK"); | ||
* Object[] result = client.exec(transaction).get(); | ||
* assert result == null; // null is returned when the watched key is modified before transaction execution. | ||
* }</pre> | ||
*/ | ||
CompletableFuture<String> watch(String[] keys); | ||
|
||
/** | ||
* Flushes all the previously watched keys for a transaction. Executing a transaction will | ||
* automatically flush all previously watched keys. | ||
* | ||
* @see <a href="https://redis.io/docs/latest/commands/unwatch/">redis.io</a> for details. | ||
* @return <code>OK</code>. | ||
* @example | ||
* <pre>{@code | ||
* assert client.watch(new String[] {"sampleKey"}).get().equals("OK"); | ||
* assert client.unwatch().get().equals("OK"); // Flushes "sampleKey" from watched keys. | ||
* }</pre> | ||
*/ | ||
CompletableFuture<String> unwatch(); | ||
} |
43 changes: 43 additions & 0 deletions
43
java/client/src/main/java/glide/api/commands/TransactionsClusterCommands.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0 */ | ||
package glide.api.commands; | ||
|
||
import glide.api.models.configuration.RequestRoutingConfiguration.Route; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
/** | ||
* Supports commands for the "Transactions Commands" group for cluster clients. | ||
* | ||
* @see <a href="https://redis.io/commands/?group=transactions">Transactions Commands</a> | ||
*/ | ||
public interface TransactionsClusterCommands { | ||
/** | ||
* Flushes all the previously watched keys for a transaction. Executing a transaction will | ||
* automatically flush all previously watched keys. The command will be routed to all primary | ||
* nodes. | ||
* | ||
* @see <a href="https://redis.io/docs/latest/commands/unwatch/">redis.io</a> for details. | ||
* @return <code>OK</code>. | ||
* @example | ||
* <pre>{@code | ||
* assert client.watch(new String[] {"sampleKey"}).get().equals("OK"); | ||
* assert client.unwatch().get().equals("OK"); // Flushes "sampleKey" from watched keys. | ||
* }</pre> | ||
*/ | ||
CompletableFuture<String> unwatch(); | ||
|
||
/** | ||
* Flushes all the previously watched keys for a transaction. Executing a transaction will | ||
* automatically flush all previously watched keys. | ||
* | ||
* @see <a href="https://redis.io/docs/latest/commands/unwatch/">redis.io</a> for details. | ||
* @param route Specifies the routing configuration for the command. The client will route the | ||
* command to the nodes defined by <code>route</code>. | ||
* @return <code>OK</code>. | ||
* @example | ||
* <pre>{@code | ||
* assert client.watch(new String[] {"sampleKey"}).get().equals("OK"); | ||
* assert client.unwatch(ALL_PRIMARIES).get().equals("OK"); // Flushes "sampleKey" from watched keys for all primary nodes. | ||
* }</pre> | ||
*/ | ||
CompletableFuture<String> unwatch(Route route); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.