diff --git a/glide-core/src/protobuf/redis_request.proto b/glide-core/src/protobuf/redis_request.proto index 32d945d254..76474fca61 100644 --- a/glide-core/src/protobuf/redis_request.proto +++ b/glide-core/src/protobuf/redis_request.proto @@ -203,6 +203,7 @@ enum RequestType { FunctionKill = 161; FunctionStats = 162; FCallReadOnly = 163; + FlushDB = 164; LSet = 165; XDel = 166; XRange = 167; diff --git a/glide-core/src/request_type.rs b/glide-core/src/request_type.rs index 7f9a3d8539..11a2c9ebfe 100644 --- a/glide-core/src/request_type.rs +++ b/glide-core/src/request_type.rs @@ -173,6 +173,7 @@ pub enum RequestType { FunctionKill = 161, FunctionStats = 162, FCallReadOnly = 163, + FlushDB = 164, LSet = 165, XDel = 166, XRange = 167, @@ -365,6 +366,7 @@ impl From<::protobuf::EnumOrUnknown> for RequestType { ProtobufRequestType::FunctionKill => RequestType::FunctionKill, ProtobufRequestType::FunctionStats => RequestType::FunctionStats, ProtobufRequestType::FCallReadOnly => RequestType::FCallReadOnly, + ProtobufRequestType::FlushDB => RequestType::FlushDB, ProtobufRequestType::LSet => RequestType::LSet, ProtobufRequestType::XDel => RequestType::XDel, ProtobufRequestType::XRange => RequestType::XRange, @@ -554,6 +556,7 @@ impl RequestType { RequestType::FunctionKill => Some(get_two_word_command("FUNCTION", "KILL")), RequestType::FunctionStats => Some(get_two_word_command("FUNCTION", "STATS")), RequestType::FCallReadOnly => Some(cmd("FCALL_RO")), + RequestType::FlushDB => Some(cmd("FLUSHDB")), RequestType::LSet => Some(cmd("LSET")), RequestType::XDel => Some(cmd("XDEL")), RequestType::XRange => Some(cmd("XRANGE")), diff --git a/java/client/src/main/java/glide/api/RedisClient.java b/java/client/src/main/java/glide/api/RedisClient.java index 9750b8a19d..7c8446e3b0 100644 --- a/java/client/src/main/java/glide/api/RedisClient.java +++ b/java/client/src/main/java/glide/api/RedisClient.java @@ -18,6 +18,7 @@ import static redis_request.RedisRequestOuterClass.RequestType.DBSize; import static redis_request.RedisRequestOuterClass.RequestType.Echo; import static redis_request.RedisRequestOuterClass.RequestType.FlushAll; +import static redis_request.RedisRequestOuterClass.RequestType.FlushDB; import static redis_request.RedisRequestOuterClass.RequestType.FunctionDelete; import static redis_request.RedisRequestOuterClass.RequestType.FunctionFlush; import static redis_request.RedisRequestOuterClass.RequestType.FunctionKill; @@ -172,6 +173,17 @@ public CompletableFuture flushall(@NonNull FlushMode mode) { FlushAll, new String[] {mode.toString()}, this::handleStringResponse); } + @Override + public CompletableFuture flushdb() { + return commandManager.submitNewCommand(FlushDB, new String[0], this::handleStringResponse); + } + + @Override + public CompletableFuture flushdb(@NonNull FlushMode mode) { + return commandManager.submitNewCommand( + FlushDB, new String[] {mode.toString()}, this::handleStringResponse); + } + @Override public CompletableFuture lolwut() { return commandManager.submitNewCommand(Lolwut, new String[0], this::handleStringResponse); diff --git a/java/client/src/main/java/glide/api/RedisClusterClient.java b/java/client/src/main/java/glide/api/RedisClusterClient.java index e4400e85be..69db834ed7 100644 --- a/java/client/src/main/java/glide/api/RedisClusterClient.java +++ b/java/client/src/main/java/glide/api/RedisClusterClient.java @@ -21,6 +21,7 @@ import static redis_request.RedisRequestOuterClass.RequestType.FCall; import static redis_request.RedisRequestOuterClass.RequestType.FCallReadOnly; import static redis_request.RedisRequestOuterClass.RequestType.FlushAll; +import static redis_request.RedisRequestOuterClass.RequestType.FlushDB; import static redis_request.RedisRequestOuterClass.RequestType.FunctionDelete; import static redis_request.RedisRequestOuterClass.RequestType.FunctionFlush; import static redis_request.RedisRequestOuterClass.RequestType.FunctionKill; @@ -343,6 +344,30 @@ public CompletableFuture flushall( FlushAll, new String[] {mode.toString()}, route, this::handleStringResponse); } + @Override + public CompletableFuture flushdb() { + return commandManager.submitNewCommand(FlushDB, new String[0], this::handleStringResponse); + } + + @Override + public CompletableFuture flushdb(@NonNull FlushMode mode) { + return commandManager.submitNewCommand( + FlushDB, new String[] {mode.toString()}, this::handleStringResponse); + } + + @Override + public CompletableFuture flushdb(@NonNull SingleNodeRoute route) { + return commandManager.submitNewCommand( + FlushDB, new String[0], route, this::handleStringResponse); + } + + @Override + public CompletableFuture flushdb( + @NonNull FlushMode mode, @NonNull SingleNodeRoute route) { + return commandManager.submitNewCommand( + FlushDB, new String[] {mode.toString()}, route, this::handleStringResponse); + } + @Override public CompletableFuture lolwut() { return commandManager.submitNewCommand(Lolwut, new String[0], this::handleStringResponse); diff --git a/java/client/src/main/java/glide/api/commands/ServerManagementClusterCommands.java b/java/client/src/main/java/glide/api/commands/ServerManagementClusterCommands.java index edfd1cd5d7..d8a7a40b88 100644 --- a/java/client/src/main/java/glide/api/commands/ServerManagementClusterCommands.java +++ b/java/client/src/main/java/glide/api/commands/ServerManagementClusterCommands.java @@ -353,7 +353,7 @@ public interface ServerManagementClusterCommands { * * @see valkey.io for details. * @param route Specifies the routing configuration for the command. The client will route the - * command to the nodes defined by route. + * command to the node defined by route. * @return OK. * @example *
{@code
@@ -371,7 +371,7 @@ public interface ServerManagementClusterCommands {
      * @param mode The flushing mode, could be either {@link FlushMode#SYNC} or {@link
      *     FlushMode#ASYNC}.
      * @param route Specifies the routing configuration for the command. The client will route the
-     *     command to the nodes defined by route.
+     *     command to the node defined by route.
      * @return OK.
      * @example
      *     
{@code
@@ -382,6 +382,70 @@ public interface ServerManagementClusterCommands {
      */
     CompletableFuture flushall(FlushMode mode, SingleNodeRoute route);
 
+    /**
+     * Deletes all the keys of the currently selected database. This command never fails.
+ * The command will be routed to all primary nodes. + * + * @see valkey.io for details. + * @return OK. + * @example + *
{@code
+     * String response = client.flushdb().get();
+     * assert response.equals("OK");
+     * }
+ */ + CompletableFuture flushdb(); + + /** + * Deletes all the keys of the currently selected database. This command never fails.
+ * The command will be routed to all primary nodes. + * + * @see valkey.io for details. + * @param mode The flushing mode, could be either {@link FlushMode#SYNC} or {@link + * FlushMode#ASYNC}. + * @return OK. + * @example + *
{@code
+     * String response = client.flushdb(ASYNC).get();
+     * assert response.equals("OK");
+     * }
+ */ + CompletableFuture flushdb(FlushMode mode); + + /** + * Deletes all the keys of the currently selected database. This command never fails. + * + * @see valkey.io for details. + * @param route Specifies the routing configuration for the command. The client will route the + * command to the node defined by route. + * @return OK. + * @example + *
{@code
+     * Route route = new SlotKeyRoute("key", PRIMARY);
+     * String response = client.flushdb(route).get();
+     * assert response.equals("OK");
+     * }
+ */ + CompletableFuture flushdb(SingleNodeRoute route); + + /** + * Deletes all the keys of the currently selected database. This command never fails. + * + * @see valkey.io for details. + * @param mode The flushing mode, could be either {@link FlushMode#SYNC} or {@link + * FlushMode#ASYNC}. + * @param route Specifies the routing configuration for the command. The client will route the + * command to the node defined by route. + * @return OK. + * @example + *
{@code
+     * Route route = new SlotKeyRoute("key", PRIMARY);
+     * String response = client.flushdb(SYNC, route).get();
+     * assert response.equals("OK");
+     * }
+ */ + CompletableFuture flushdb(FlushMode mode, SingleNodeRoute route); + /** * Displays a piece of generative computer art and the Redis version.
* The command will be routed to a random node. diff --git a/java/client/src/main/java/glide/api/commands/ServerManagementCommands.java b/java/client/src/main/java/glide/api/commands/ServerManagementCommands.java index d59568eb73..b38b46564f 100644 --- a/java/client/src/main/java/glide/api/commands/ServerManagementCommands.java +++ b/java/client/src/main/java/glide/api/commands/ServerManagementCommands.java @@ -180,6 +180,34 @@ public interface ServerManagementCommands { */ CompletableFuture flushall(FlushMode mode); + /** + * Deletes all the keys of the currently selected database. This command never fails. + * + * @see valkey.io for details. + * @return OK. + * @example + *
{@code
+     * String response = client.flushdb().get();
+     * assert response.equals("OK");
+     * }
+ */ + CompletableFuture flushdb(); + + /** + * Deletes all the keys of the currently selected database. This command never fails. + * + * @see valkey.io for details. + * @param mode The flushing mode, could be either {@link FlushMode#SYNC} or {@link + * FlushMode#ASYNC}. + * @return OK. + * @example + *
{@code
+     * String response = client.flushdb(ASYNC).get();
+     * assert response.equals("OK");
+     * }
+ */ + CompletableFuture flushdb(FlushMode mode); + /** * Displays a piece of generative computer art and the Redis version. * diff --git a/java/client/src/main/java/glide/api/models/BaseTransaction.java b/java/client/src/main/java/glide/api/models/BaseTransaction.java index 69bc518b62..7ad4861a35 100644 --- a/java/client/src/main/java/glide/api/models/BaseTransaction.java +++ b/java/client/src/main/java/glide/api/models/BaseTransaction.java @@ -53,6 +53,7 @@ import static redis_request.RedisRequestOuterClass.RequestType.FCall; import static redis_request.RedisRequestOuterClass.RequestType.FCallReadOnly; import static redis_request.RedisRequestOuterClass.RequestType.FlushAll; +import static redis_request.RedisRequestOuterClass.RequestType.FlushDB; import static redis_request.RedisRequestOuterClass.RequestType.FunctionDelete; import static redis_request.RedisRequestOuterClass.RequestType.FunctionFlush; import static redis_request.RedisRequestOuterClass.RequestType.FunctionList; @@ -3027,6 +3028,30 @@ public T flushall(FlushMode mode) { return getThis(); } + /** + * Deletes all the keys of the currently selected database. This command never fails. + * + * @see valkey.io for details. + * @return Command Response - OK. + */ + public T flushdb() { + protobufTransaction.addCommands(buildCommand(FlushDB)); + return getThis(); + } + + /** + * Deletes all the keys of the currently selected database. This command never fails. + * + * @see valkey.io for details. + * @param mode The flushing mode, could be either {@link FlushMode#SYNC} or {@link + * FlushMode#ASYNC}. + * @return Command Response - OK. + */ + public T flushdb(FlushMode mode) { + protobufTransaction.addCommands(buildCommand(FlushDB, buildArgs(mode.toString()))); + return getThis(); + } + /** * Displays a piece of generative computer art and the Redis version. * diff --git a/java/client/src/main/java/glide/api/models/commands/FlushMode.java b/java/client/src/main/java/glide/api/models/commands/FlushMode.java index 69fc260ecd..b371abbd65 100644 --- a/java/client/src/main/java/glide/api/models/commands/FlushMode.java +++ b/java/client/src/main/java/glide/api/models/commands/FlushMode.java @@ -14,16 +14,24 @@ *
  • FLUSHALL command implemented by {@link RedisClient#flushall(FlushMode)}, * {@link RedisClusterClient#flushall(FlushMode)}, and {@link * RedisClusterClient#flushall(FlushMode, SingleNodeRoute)}. + *
  • FLUSHDB command implemented by {@link RedisClient#flushdb(FlushMode)}, {@link + * RedisClusterClient#flushdb(FlushMode)}, and {@link RedisClusterClient#flushdb(FlushMode, + * SingleNodeRoute)}. *
  • FUNCTION FLUSH command implemented by {@link * RedisClient#functionFlush(FlushMode)}, {@link RedisClusterClient#functionFlush(FlushMode)}, * and {@link RedisClusterClient#functionFlush(FlushMode, Route)}. * * - * @see valkey.io and valkey.io + * @see flushall, flushdb, and function flush at valkey.io */ public enum FlushMode { - /** Flushes synchronously. */ + /** + * Flushes synchronously. + * + * @since Redis 6.2 and above. + */ SYNC, /** Flushes asynchronously. */ ASYNC diff --git a/java/client/src/main/java/glide/api/models/configuration/RequestRoutingConfiguration.java b/java/client/src/main/java/glide/api/models/configuration/RequestRoutingConfiguration.java index bea04a7e75..6af6366be8 100644 --- a/java/client/src/main/java/glide/api/models/configuration/RequestRoutingConfiguration.java +++ b/java/client/src/main/java/glide/api/models/configuration/RequestRoutingConfiguration.java @@ -31,7 +31,12 @@ public interface MultiNodeRoute extends Route {} @RequiredArgsConstructor @Getter public enum SimpleSingleNodeRoute implements SingleNodeRoute { - /** Route request to a random node. */ + /** + * Route request to a random node.
    + * Warning
    + * Don't use it with write commands, because they could be randomly routed to a replica (RO) + * node and fail. + */ RANDOM(2); private final int ordinal; @@ -40,7 +45,10 @@ public enum SimpleSingleNodeRoute implements SingleNodeRoute { @RequiredArgsConstructor @Getter public enum SimpleMultiNodeRoute implements MultiNodeRoute { - /** Route request to all nodes. */ + /** + * Route request to all nodes. Warning
    + * Don't use it with write commands, they could be routed to a replica (RO) node and fail. + */ ALL_NODES(0), /** Route request to all primary nodes. */ ALL_PRIMARIES(1); diff --git a/java/client/src/test/java/glide/api/RedisClientTest.java b/java/client/src/test/java/glide/api/RedisClientTest.java index 4d969a9b7a..26fc140995 100644 --- a/java/client/src/test/java/glide/api/RedisClientTest.java +++ b/java/client/src/test/java/glide/api/RedisClientTest.java @@ -85,6 +85,7 @@ import static redis_request.RedisRequestOuterClass.RequestType.FCall; import static redis_request.RedisRequestOuterClass.RequestType.FCallReadOnly; import static redis_request.RedisRequestOuterClass.RequestType.FlushAll; +import static redis_request.RedisRequestOuterClass.RequestType.FlushDB; import static redis_request.RedisRequestOuterClass.RequestType.FunctionDelete; import static redis_request.RedisRequestOuterClass.RequestType.FunctionFlush; import static redis_request.RedisRequestOuterClass.RequestType.FunctionKill; @@ -4517,6 +4518,47 @@ public void flushall_with_mode_returns_success() { assertEquals(OK, payload); } + @SneakyThrows + @Test + public void flushdb_returns_success() { + // setup + CompletableFuture testResponse = new CompletableFuture<>(); + testResponse.complete(OK); + + // match on protobuf request + when(commandManager.submitNewCommand(eq(FlushDB), eq(new String[0]), any())) + .thenReturn(testResponse); + + // exercise + CompletableFuture response = service.flushdb(); + String payload = response.get(); + + // verify + assertEquals(testResponse, response); + assertEquals(OK, payload); + } + + @SneakyThrows + @Test + public void flushdb_with_mode_returns_success() { + // setup + CompletableFuture testResponse = new CompletableFuture<>(); + testResponse.complete(OK); + + // match on protobuf request + when(commandManager.submitNewCommand( + eq(FlushDB), eq(new String[] {SYNC.toString()}), any())) + .thenReturn(testResponse); + + // exercise + CompletableFuture response = service.flushdb(SYNC); + String payload = response.get(); + + // verify + assertEquals(testResponse, response); + assertEquals(OK, payload); + } + @SneakyThrows @Test public void lolwut_returns_success() { diff --git a/java/client/src/test/java/glide/api/RedisClusterClientTest.java b/java/client/src/test/java/glide/api/RedisClusterClientTest.java index fdca5bbc5f..ab1199c081 100644 --- a/java/client/src/test/java/glide/api/RedisClusterClientTest.java +++ b/java/client/src/test/java/glide/api/RedisClusterClientTest.java @@ -29,6 +29,7 @@ import static redis_request.RedisRequestOuterClass.RequestType.FCall; import static redis_request.RedisRequestOuterClass.RequestType.FCallReadOnly; import static redis_request.RedisRequestOuterClass.RequestType.FlushAll; +import static redis_request.RedisRequestOuterClass.RequestType.FlushDB; import static redis_request.RedisRequestOuterClass.RequestType.FunctionDelete; import static redis_request.RedisRequestOuterClass.RequestType.FunctionFlush; import static redis_request.RedisRequestOuterClass.RequestType.FunctionKill; @@ -919,6 +920,88 @@ public void flushall_with_route_and_mode_returns_success() { assertEquals(OK, payload); } + @SneakyThrows + @Test + public void flushdb_returns_success() { + // setup + CompletableFuture testResponse = new CompletableFuture<>(); + testResponse.complete(OK); + + // match on protobuf request + when(commandManager.submitNewCommand(eq(FlushDB), eq(new String[0]), any())) + .thenReturn(testResponse); + + // exercise + CompletableFuture response = service.flushdb(); + String payload = response.get(); + + // verify + assertEquals(testResponse, response); + assertEquals(OK, payload); + } + + @SneakyThrows + @Test + public void flushdb_with_mode_returns_success() { + // setup + CompletableFuture testResponse = new CompletableFuture<>(); + testResponse.complete(OK); + + // match on protobuf request + when(commandManager.submitNewCommand( + eq(FlushDB), eq(new String[] {SYNC.toString()}), any())) + .thenReturn(testResponse); + + // exercise + CompletableFuture response = service.flushdb(SYNC); + String payload = response.get(); + + // verify + assertEquals(testResponse, response); + assertEquals(OK, payload); + } + + @SneakyThrows + @Test + public void flushdb_with_route_returns_success() { + // setup + CompletableFuture testResponse = new CompletableFuture<>(); + testResponse.complete(OK); + + // match on protobuf request + when(commandManager.submitNewCommand(eq(FlushDB), eq(new String[0]), eq(RANDOM), any())) + .thenReturn(testResponse); + + // exercise + CompletableFuture response = service.flushdb(RANDOM); + String payload = response.get(); + + // verify + assertEquals(testResponse, response); + assertEquals(OK, payload); + } + + @SneakyThrows + @Test + public void flushdb_with_route_and_mode_returns_success() { + // setup + CompletableFuture testResponse = new CompletableFuture<>(); + testResponse.complete(OK); + + // match on protobuf request + when(commandManager.submitNewCommand( + eq(FlushDB), eq(new String[] {SYNC.toString()}), eq(RANDOM), any())) + .thenReturn(testResponse); + + // exercise + CompletableFuture response = service.flushdb(SYNC, RANDOM); + String payload = response.get(); + + // verify + assertEquals(testResponse, response); + assertEquals(OK, payload); + } + @SneakyThrows @Test public void lolwut_returns_success() { diff --git a/java/client/src/test/java/glide/api/models/TransactionTests.java b/java/client/src/test/java/glide/api/models/TransactionTests.java index 4ee7f045c6..a82c85f6d8 100644 --- a/java/client/src/test/java/glide/api/models/TransactionTests.java +++ b/java/client/src/test/java/glide/api/models/TransactionTests.java @@ -65,6 +65,7 @@ import static redis_request.RedisRequestOuterClass.RequestType.FCall; import static redis_request.RedisRequestOuterClass.RequestType.FCallReadOnly; import static redis_request.RedisRequestOuterClass.RequestType.FlushAll; +import static redis_request.RedisRequestOuterClass.RequestType.FlushDB; import static redis_request.RedisRequestOuterClass.RequestType.FunctionDelete; import static redis_request.RedisRequestOuterClass.RequestType.FunctionFlush; import static redis_request.RedisRequestOuterClass.RequestType.FunctionList; @@ -763,6 +764,10 @@ InfScoreBound.NEGATIVE_INFINITY, new ScoreBoundary(3, false), new Limit(1, 2)), results.add(Pair.of(FlushAll, buildArgs())); results.add(Pair.of(FlushAll, buildArgs(ASYNC.toString()))); + transaction.flushdb().flushdb(ASYNC); + results.add(Pair.of(FlushDB, buildArgs())); + results.add(Pair.of(FlushDB, buildArgs(ASYNC.toString()))); + transaction.lolwut().lolwut(5).lolwut(new int[] {1, 2}).lolwut(6, new int[] {42}); results.add(Pair.of(Lolwut, buildArgs())); results.add(Pair.of(Lolwut, buildArgs(VERSION_REDIS_API, "5"))); diff --git a/java/integTest/src/test/java/glide/TransactionTestUtilities.java b/java/integTest/src/test/java/glide/TransactionTestUtilities.java index 71de90dfb8..0d07778a14 100644 --- a/java/integTest/src/test/java/glide/TransactionTestUtilities.java +++ b/java/integTest/src/test/java/glide/TransactionTestUtilities.java @@ -668,6 +668,8 @@ private static Object[] serverManagementCommands(BaseTransaction transaction) .lolwut(1) .flushall() .flushall(ASYNC) + .flushdb() + .flushdb(ASYNC) .dbsize(); return new Object[] { @@ -677,6 +679,8 @@ private static Object[] serverManagementCommands(BaseTransaction transaction) "Redis ver. " + REDIS_VERSION + '\n', // lolwut(1) OK, // flushall() OK, // flushall(ASYNC) + OK, // flushdb() + OK, // flushdb(ASYNC) 0L, // dbsize() }; } diff --git a/java/integTest/src/test/java/glide/cluster/CommandTests.java b/java/integTest/src/test/java/glide/cluster/CommandTests.java index e0bd4d69e8..007820007b 100644 --- a/java/integTest/src/test/java/glide/cluster/CommandTests.java +++ b/java/integTest/src/test/java/glide/cluster/CommandTests.java @@ -43,7 +43,6 @@ import glide.api.RedisClusterClient; import glide.api.models.ClusterTransaction; import glide.api.models.ClusterValue; -import glide.api.models.commands.FlushMode; import glide.api.models.commands.InfoOptions; import glide.api.models.commands.ListDirection; import glide.api.models.commands.RangeOptions.RangeByIndex; @@ -642,7 +641,9 @@ public void lolwut_lolwut() { @Test @SneakyThrows - public void dbsize() { + public void dbsize_and_flushdb() { + boolean is62orHigher = REDIS_VERSION.isGreaterThanOrEqualTo("6.2.0"); + assertEquals(OK, clusterClient.flushall().get()); // dbsize should be 0 after flushall() because all keys have been deleted assertEquals(0L, clusterClient.dbsize().get()); @@ -655,11 +656,41 @@ public void dbsize() { // test dbsize with routing - flush the database first to ensure the set() call is directed to a // node with 0 keys. - assertEquals(OK, clusterClient.flushall().get()); + assertEquals(OK, clusterClient.flushdb().get()); assertEquals(0L, clusterClient.dbsize().get()); + String key = UUID.randomUUID().toString(); + SingleNodeRoute route = new SlotKeyRoute(key, PRIMARY); + + // add a key, measure DB size, flush DB and measure again - with all arg combinations + assertEquals(OK, clusterClient.set(key, "foo").get()); + assertEquals(1L, clusterClient.dbsize(route).get()); + if (is62orHigher) { + assertEquals(OK, clusterClient.flushdb(SYNC).get()); + } else { + assertEquals(OK, clusterClient.flushdb(ASYNC).get()); + } + assertEquals(0L, clusterClient.dbsize().get()); + + assertEquals(OK, clusterClient.set(key, "foo").get()); + assertEquals(1L, clusterClient.dbsize(route).get()); + assertEquals(OK, clusterClient.flushdb(route).get()); + assertEquals(0L, clusterClient.dbsize(route).get()); + assertEquals(OK, clusterClient.set(key, "foo").get()); - assertEquals(1L, clusterClient.dbsize(new SlotKeyRoute(key, PRIMARY)).get()); + assertEquals(1L, clusterClient.dbsize(route).get()); + if (is62orHigher) { + assertEquals(OK, clusterClient.flushdb(SYNC, route).get()); + } else { + assertEquals(OK, clusterClient.flushdb(ASYNC, route).get()); + } + assertEquals(0L, clusterClient.dbsize(route).get()); + + if (!is62orHigher) { + var executionException = + assertThrows(ExecutionException.class, () -> clusterClient.flushdb(SYNC).get()); + assertInstanceOf(RequestException.class, executionException.getCause()); + } } @Test @@ -796,7 +827,14 @@ public void check_does_not_throw_cross_slot_error(String testName, CompletableFu @Test @SneakyThrows public void flushall() { - assertEquals(OK, clusterClient.flushall(FlushMode.SYNC).get()); + if (REDIS_VERSION.isGreaterThanOrEqualTo("6.2.0")) { + assertEquals(OK, clusterClient.flushall(SYNC).get()); + } else { + var executionException = + assertThrows(ExecutionException.class, () -> clusterClient.flushall(SYNC).get()); + assertInstanceOf(RequestException.class, executionException.getCause()); + assertEquals(OK, clusterClient.flushall(ASYNC).get()); + } // TODO replace with KEYS command when implemented Object[] keysAfter = diff --git a/java/integTest/src/test/java/glide/standalone/CommandTests.java b/java/integTest/src/test/java/glide/standalone/CommandTests.java index dc91dd2d78..7564374995 100644 --- a/java/integTest/src/test/java/glide/standalone/CommandTests.java +++ b/java/integTest/src/test/java/glide/standalone/CommandTests.java @@ -343,18 +343,41 @@ public void lolwut_lolwut() { @Test @SneakyThrows - public void dbsize() { + public void dbsize_and_flushdb() { assertEquals(OK, regularClient.flushall().get()); assertEquals(OK, regularClient.select(0).get()); + // fill DB and check size int numKeys = 10; for (int i = 0; i < numKeys; i++) { assertEquals(OK, regularClient.set(UUID.randomUUID().toString(), "foo").get()); } assertEquals(10L, regularClient.dbsize().get()); + // check another empty DB assertEquals(OK, regularClient.select(1).get()); assertEquals(0L, regularClient.dbsize().get()); + + // check non-empty + assertEquals(OK, regularClient.set(UUID.randomUUID().toString(), "foo").get()); + assertEquals(1L, regularClient.dbsize().get()); + + // flush and check again + if (REDIS_VERSION.isGreaterThanOrEqualTo("6.2.0")) { + assertEquals(OK, regularClient.flushdb(SYNC).get()); + } else { + var executionException = + assertThrows(ExecutionException.class, () -> regularClient.flushdb(SYNC).get()); + assertInstanceOf(RequestException.class, executionException.getCause()); + assertEquals(OK, regularClient.flushdb(ASYNC).get()); + } + assertEquals(0L, regularClient.dbsize().get()); + + // switch to DB 0 and flush and check + assertEquals(OK, regularClient.select(0).get()); + assertEquals(10L, regularClient.dbsize().get()); + assertEquals(OK, regularClient.flushdb().get()); + assertEquals(0L, regularClient.dbsize().get()); } @Test @@ -376,7 +399,14 @@ public void objectFreq() { @Test @SneakyThrows public void flushall() { - assertEquals(OK, regularClient.flushall(SYNC).get()); + if (REDIS_VERSION.isGreaterThanOrEqualTo("6.2.0")) { + assertEquals(OK, regularClient.flushall(SYNC).get()); + } else { + var executionException = + assertThrows(ExecutionException.class, () -> regularClient.flushall(SYNC).get()); + assertInstanceOf(RequestException.class, executionException.getCause()); + assertEquals(OK, regularClient.flushall(ASYNC).get()); + } // TODO replace with KEYS command when implemented Object[] keysAfter = (Object[]) regularClient.customCommand(new String[] {"keys", "*"}).get(); @@ -521,7 +551,7 @@ public void copy() { } } - // @Test + @Test @SneakyThrows public void functionStats_and_functionKill() { assumeTrue(REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0"), "This feature added in redis 7");