-
Notifications
You must be signed in to change notification settings - Fork 68
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
Java: Add WATCH
and UNWATCH
command
#1539
Merged
+381
−26
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
19c268e
Java: Add `WATCH` and `UNWATCH` command
GumpacG 7512f79
Addressed PR comments
GumpacG 2d743eb
Added unwatch with route and improved tests
GumpacG 9e226a6
Fixed test based on submodule changes
GumpacG 59e987d
Addressed PR comments
GumpacG f593e3d
Added example for watch returning null
GumpacG 5d28b00
Added crossSlot test
GumpacG 971c85d
Addressed comments
GumpacG 396e1da
Commented out a test due to a bug
GumpacG f605ee6
Address PR comments
GumpacG File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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. | ||
* | ||
GumpacG marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBD do we need this? Does user need this?