Skip to content

Commit

Permalink
Address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
GumpacG committed Jun 17, 2024
1 parent 396e1da commit f605ee6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@
* @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.
Expand Down
20 changes: 20 additions & 0 deletions java/client/src/test/java/glide/api/RedisClusterClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1454,6 +1454,26 @@ public void functionDelete_with_route_returns_success() {
assertEquals(OK, payload);
}

@SneakyThrows
@Test
public void unwatch_returns_success() {
// setup
CompletableFuture<String> testResponse = new CompletableFuture<>();
testResponse.complete(OK);

// match on protobuf request
when(commandManager.<String>submitNewCommand(eq(UnWatch), eq(new String[0]), any()))
.thenReturn(testResponse);

// exercise
CompletableFuture<String> response = service.unwatch();
String payload = response.get();

// verify
assertEquals(testResponse, response);
assertEquals(OK, payload);
}

@SneakyThrows
@Test
public void unwatch_with_route_returns_success() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ public void unwatch() {
// Transaction executes successfully after modifying a watched key then calling UNWATCH
assertEquals(OK, clusterClient.watch(keys).get());
assertEquals(OK, clusterClient.set(key2, helloString).get());
assertEquals(OK, clusterClient.unwatch().get());
assertEquals(OK, clusterClient.unwatch(ALL_PRIMARIES).get());
setFoobarTransaction.set(key1, foobarString).set(key2, foobarString);
assertArrayEquals(expectedExecResponse, clusterClient.exec(setFoobarTransaction).get());
Expand Down

0 comments on commit f605ee6

Please sign in to comment.