diff --git a/java/client/src/main/java/glide/api/commands/SortedSetBaseCommands.java b/java/client/src/main/java/glide/api/commands/SortedSetBaseCommands.java index 1431439c0e..dcd2fce4d5 100644 --- a/java/client/src/main/java/glide/api/commands/SortedSetBaseCommands.java +++ b/java/client/src/main/java/glide/api/commands/SortedSetBaseCommands.java @@ -423,8 +423,6 @@ CompletableFuture> zrangeWithScores( * Stores a specified range of elements from the sorted set at source, into a new * sorted set at destination. If destination doesn't exist, a new sorted * set is created; if it exists, it's overwritten.
- * ZRANGESTORE can perform different types of range queries: by index (rank), by the - * score, or by lexicographical order.
* * @see redis.io for more details. * @param destination The key for the destination sorted set. @@ -442,7 +440,7 @@ CompletableFuture> zrangeWithScores( * @example *
{@code
      * RangeByIndex query1 = new RangeByIndex(0, -1); // Query for all members.
-     * Long payload1 = client.zrange("destinationKey", "mySortedSet", query1, true).get();
+     * Long payload1 = client.zrangestore("destinationKey", "mySortedSet", query1, true).get();
      * assert payload1 == 7L;
      *
      * RangeByScore query2 = new RangeByScore(InfScoreBound.NEGATIVE_INFINITY, new ScoreBoundary(3)); // Query for members with scores within the range of negative infinity to 3.
@@ -457,8 +455,6 @@ CompletableFuture zrangestore(
      * Stores a specified range of elements from the sorted set at source, into a new
      * sorted set at destination. If destination doesn't exist, a new sorted
      * set is created; if it exists, it's overwritten.
- * ZRANGESTORE can perform different types of range queries: by index (rank), by the - * score, or by lexicographical order.
* * @see redis.io for more details. * @param destination The key for the destination sorted set. @@ -474,7 +470,7 @@ CompletableFuture zrangestore( * @example *
{@code
      * RangeByIndex query1 = new RangeByIndex(0, -1); // Query for all members.
-     * Long payload1 = client.zrange("destinationKey", "mySortedSet", query1).get();
+     * Long payload1 = client.zrangestore("destinationKey", "mySortedSet", query1).get();
      * assert payload1 == 7L;
      *
      * RangeByScore query2 = new RangeByScore(InfScoreBound.NEGATIVE_INFINITY, new ScoreBoundary(3)); // Query for members with scores within the range of negative infinity to 3.
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 d256cc5b3c..8f5b26a410 100644
--- a/java/client/src/main/java/glide/api/models/BaseTransaction.java
+++ b/java/client/src/main/java/glide/api/models/BaseTransaction.java
@@ -1512,30 +1512,6 @@ public T zrankWithScore(@NonNull String key, @NonNull String member) {
         return getThis();
     }
 
-    /**
-     * Stores a specified range of elements from the sorted set at source, into a new
-     * sorted set at destination. If destination doesn't exist, a new sorted
-     * set is created; if it exists, it's overwritten.
- * ZRANGESTORE can perform different types of range queries: by index (rank), by the - * score, or by lexicographical order.
- * - * @see redis.io for more details. - * @param destination The key for the destination sorted set. - * @param source The key of the source sorted set. - * @param rangeQuery The range query object representing the type of range query to perform.
- *
    - *
  • For range queries by index (rank), use {@link RangeByIndex}. - *
  • For range queries by lexicographical order, use {@link RangeByLex}. - *
  • For range queries by score, use {@link RangeByScore}. - *
- * - * @return Command Response - The number of elements in the resulting sorted set. - */ - public T zrangestore( - @NonNull String destination, @NonNull String source, @NonNull RangeQuery rangeQuery) { - return getThis().zrangestore(destination, source, rangeQuery, false); - } - /** * Returns the scores associated with the specified members in the sorted set stored * at key. @@ -1684,6 +1660,30 @@ public T zrangestore( return getThis(); } + /** + * Stores a specified range of elements from the sorted set at source, into a new + * sorted set at destination. If destination doesn't exist, a new sorted + * set is created; if it exists, it's overwritten.
+ * ZRANGESTORE can perform different types of range queries: by index (rank), by the + * score, or by lexicographical order.
+ * + * @see redis.io for more details. + * @param destination The key for the destination sorted set. + * @param source The key of the source sorted set. + * @param rangeQuery The range query object representing the type of range query to perform.
+ *
    + *
  • For range queries by index (rank), use {@link RangeByIndex}. + *
  • For range queries by lexicographical order, use {@link RangeByLex}. + *
  • For range queries by score, use {@link RangeByScore}. + *
+ * + * @return Command Response - The number of elements in the resulting sorted set. + */ + public T zrangestore( + @NonNull String destination, @NonNull String source, @NonNull RangeQuery rangeQuery) { + return getThis().zrangestore(destination, source, rangeQuery, false); + } + /** * Removes all elements in the sorted set stored at key with a lexicographical order * between minLex and maxLex. diff --git a/java/client/src/test/java/glide/api/RedisClientTest.java b/java/client/src/test/java/glide/api/RedisClientTest.java index 22990ce85a..0639d5e245 100644 --- a/java/client/src/test/java/glide/api/RedisClientTest.java +++ b/java/client/src/test/java/glide/api/RedisClientTest.java @@ -2511,25 +2511,22 @@ public void zremrangebylex_returns_success() { @SneakyThrows @Test - public void zrangestore_by_lex_returns_success() { + public void zremrangebyscore_returns_success() { // setup - String source = "testSourceKey"; - String destination = "testDestinationKey"; - RangeByLex rangeByLex = - new RangeByLex(InfLexBound.NEGATIVE_INFINITY, new LexBoundary("c", false)); - String[] arguments = - new String[] {source, destination, rangeByLex.getStart(), rangeByLex.getEnd(), "BYLEX"}; - Long value = 2L; + String key = "testKey"; + String[] arguments = new String[] {key, "-inf", "10.0"}; + Long value = 3L; CompletableFuture testResponse = new CompletableFuture<>(); testResponse.complete(value); // match on protobuf request - when(commandManager.submitNewCommand(eq(ZRangeStore), eq(arguments), any())) + when(commandManager.submitNewCommand(eq(ZRemRangeByScore), eq(arguments), any())) .thenReturn(testResponse); // exercise - CompletableFuture response = service.zrangestore(source, destination, rangeByLex); + CompletableFuture response = + service.zremrangebyscore(key, InfScoreBound.NEGATIVE_INFINITY, new ScoreBoundary(10, true)); Long payload = response.get(); // verify @@ -2539,22 +2536,25 @@ public void zrangestore_by_lex_returns_success() { @SneakyThrows @Test - public void zremrangebyscore_returns_success() { + public void zrangestore_by_lex_returns_success() { // setup - String key = "testKey"; - String[] arguments = new String[] {key, "-inf", "10.0"}; - Long value = 3L; + String source = "testSourceKey"; + String destination = "testDestinationKey"; + RangeByLex rangeByLex = + new RangeByLex(InfLexBound.NEGATIVE_INFINITY, new LexBoundary("c", false)); + String[] arguments = + new String[] {source, destination, rangeByLex.getStart(), rangeByLex.getEnd(), "BYLEX"}; + Long value = 2L; CompletableFuture testResponse = new CompletableFuture<>(); testResponse.complete(value); // match on protobuf request - when(commandManager.submitNewCommand(eq(ZRemRangeByScore), eq(arguments), any())) + when(commandManager.submitNewCommand(eq(ZRangeStore), eq(arguments), any())) .thenReturn(testResponse); // exercise - CompletableFuture response = - service.zremrangebyscore(key, InfScoreBound.NEGATIVE_INFINITY, new ScoreBoundary(10, true)); + CompletableFuture response = service.zrangestore(source, destination, rangeByLex); Long payload = response.get(); // verify diff --git a/java/integTest/src/test/java/glide/SharedCommandTests.java b/java/integTest/src/test/java/glide/SharedCommandTests.java index 5c6264a8e0..ead8b26cba 100644 --- a/java/integTest/src/test/java/glide/SharedCommandTests.java +++ b/java/integTest/src/test/java/glide/SharedCommandTests.java @@ -1566,45 +1566,6 @@ public void zremrangebylex(BaseClient client) { assertTrue(executionException.getCause() instanceof RequestException); } - @SneakyThrows - @ParameterizedTest - @MethodSource("getClients") - public void zrangestore_by_index(BaseClient client) { - String key = "{testKey}:" + UUID.randomUUID(); - String destination = "{testKey}:" + UUID.randomUUID(); - String source = "{testKey}:" + UUID.randomUUID(); - Map membersScores = Map.of("one", 1.0, "two", 2.0, "three", 3.0); - assertEquals(3, client.zadd(source, membersScores).get()); - - // Full range. - assertEquals(3, client.zrangestore(destination, source, new RangeByIndex(0, -1)).get()); - assertEquals( - Map.of("one", 1.0, "two", 2.0, "three", 3.0), - client.zrangeWithScores(destination, new RangeByIndex(0, -1)).get()); - - // Range from rank 0 to 1. In descending order of scores. - assertEquals(2, client.zrangestore(destination, source, new RangeByIndex(0, 1), true).get()); - assertEquals( - Map.of("three", 3.0, "two", 2.0), - client.zrangeWithScores(destination, new RangeByIndex(0, -1)).get()); - - // Incorrect range as start > stop. - assertEquals(0, client.zrangestore(destination, source, new RangeByIndex(3, 1)).get()); - assertEquals(Map.of(), client.zrangeWithScores(destination, new RangeByIndex(0, -1)).get()); - - // Non-existing source. - assertEquals(0, client.zrangestore(destination, key, new RangeByIndex(0, -1)).get()); - assertEquals(Map.of(), client.zrangeWithScores(destination, new RangeByIndex(0, -1)).get()); - - // Key exists, but it is not a set - assertEquals(OK, client.set(key, "value").get()); - ExecutionException executionException = - assertThrows( - ExecutionException.class, - () -> client.zrangestore(destination, key, new RangeByIndex(3, 1)).get()); - assertTrue(executionException.getCause() instanceof RequestException); - } - @SneakyThrows @ParameterizedTest @MethodSource("getClients") @@ -1649,6 +1610,45 @@ public void zremrangebyscore(BaseClient client) { assertTrue(executionException.getCause() instanceof RequestException); } + @SneakyThrows + @ParameterizedTest + @MethodSource("getClients") + public void zrangestore_by_index(BaseClient client) { + String key = "{testKey}:" + UUID.randomUUID(); + String destination = "{testKey}:" + UUID.randomUUID(); + String source = "{testKey}:" + UUID.randomUUID(); + Map membersScores = Map.of("one", 1.0, "two", 2.0, "three", 3.0); + assertEquals(3, client.zadd(source, membersScores).get()); + + // Full range. + assertEquals(3, client.zrangestore(destination, source, new RangeByIndex(0, -1)).get()); + assertEquals( + Map.of("one", 1.0, "two", 2.0, "three", 3.0), + client.zrangeWithScores(destination, new RangeByIndex(0, -1)).get()); + + // Range from rank 0 to 1. In descending order of scores. + assertEquals(2, client.zrangestore(destination, source, new RangeByIndex(0, 1), true).get()); + assertEquals( + Map.of("three", 3.0, "two", 2.0), + client.zrangeWithScores(destination, new RangeByIndex(0, -1)).get()); + + // Incorrect range as start > stop. + assertEquals(0, client.zrangestore(destination, source, new RangeByIndex(3, 1)).get()); + assertEquals(Map.of(), client.zrangeWithScores(destination, new RangeByIndex(0, -1)).get()); + + // Non-existing source. + assertEquals(0, client.zrangestore(destination, key, new RangeByIndex(0, -1)).get()); + assertEquals(Map.of(), client.zrangeWithScores(destination, new RangeByIndex(0, -1)).get()); + + // Key exists, but it is not a set + assertEquals(OK, client.set(key, "value").get()); + ExecutionException executionException = + assertThrows( + ExecutionException.class, + () -> client.zrangestore(destination, key, new RangeByIndex(3, 1)).get()); + assertTrue(executionException.getCause() instanceof RequestException); + } + @SneakyThrows @ParameterizedTest @MethodSource("getClients")