diff --git a/java/client/src/main/java/glide/api/commands/GenericClusterCommands.java b/java/client/src/main/java/glide/api/commands/GenericClusterCommands.java index ca0043bce7..a76290b3b3 100644 --- a/java/client/src/main/java/glide/api/commands/GenericClusterCommands.java +++ b/java/client/src/main/java/glide/api/commands/GenericClusterCommands.java @@ -114,8 +114,7 @@ public interface GenericClusterCommands { CompletableFuture exec(ClusterTransaction transaction, SingleNodeRoute route); /** - * Returns a random key from the currently selected database.
- * The command will be routed to all primary nodes, and will return the first successful result. + * Returns a random key. * * @see redis.io for details. * @param route Specifies the routing configuration for the command. The client will route the @@ -134,7 +133,8 @@ public interface GenericClusterCommands { CompletableFuture randomKey(Route route); /** - * Returns a random key. + * Returns a random key.
+ * The command will be routed to all primary nodes, and will return the first successful result. * * @see redis.io for details. * @return A random key from the database. diff --git a/java/integTest/src/test/java/glide/cluster/CommandTests.java b/java/integTest/src/test/java/glide/cluster/CommandTests.java index bddc4aed49..6f5928034e 100644 --- a/java/integTest/src/test/java/glide/cluster/CommandTests.java +++ b/java/integTest/src/test/java/glide/cluster/CommandTests.java @@ -1558,8 +1558,14 @@ public void randomKey() { String randomKey = clusterClient.randomKey().get(); assertEquals(1L, clusterClient.exists(new String[] {randomKey}).get()); + String randomKeyPrimaries = clusterClient.randomKey(ALL_PRIMARIES).get(); + assertEquals(1L, clusterClient.exists(new String[] {randomKeyPrimaries}).get()); + // no keys in database - assertEquals(OK, clusterClient.flushall().get()); - assertNull(clusterClient.randomKey().get()); + assertEquals(OK, clusterClient.flushall(SYNC).get()); + + // TODO: returns a ResponseError but expecting null + // uncomment when this is completed: https://github.com/amazon-contributing/redis-rs/pull/153 + // assertNull(clusterClient.randomKey().get()); } }