From df6702f9c836ecf6ea680100283284222178a6cb Mon Sep 17 00:00:00 2001 From: Chloe Yip Date: Thu, 4 Jul 2024 12:03:29 -0700 Subject: [PATCH 01/17] updated --- .../src/main/java/glide/api/BaseClient.java | 68 ++++++++ .../api/commands/StreamBaseCommands.java | 108 ++++++++++++ .../glide/api/models/BaseTransaction.java | 154 ++++++++++++++++++ .../test/java/glide/api/RedisClientTest.java | 37 +++++ 4 files changed, 367 insertions(+) diff --git a/java/client/src/main/java/glide/api/BaseClient.java b/java/client/src/main/java/glide/api/BaseClient.java index a37e9d2103..3f8b40fb0c 100644 --- a/java/client/src/main/java/glide/api/BaseClient.java +++ b/java/client/src/main/java/glide/api/BaseClient.java @@ -139,6 +139,7 @@ import static redis_request.RedisRequestOuterClass.RequestType.Watch; import static redis_request.RedisRequestOuterClass.RequestType.XAck; import static redis_request.RedisRequestOuterClass.RequestType.XAdd; +import static redis_request.RedisRequestOuterClass.RequestType.XAutoClaim; import static redis_request.RedisRequestOuterClass.RequestType.XClaim; import static redis_request.RedisRequestOuterClass.RequestType.XDel; import static redis_request.RedisRequestOuterClass.RequestType.XGroupCreate; @@ -2794,6 +2795,73 @@ public CompletableFuture[]> xinfoConsumers( response -> castArray(handleArrayResponseBinary(response), Map.class)); } + @Override + public CompletableFuture xautoclaim( + @NonNull String key, + @NonNull String group, + @NonNull String consumer, + long minIdleTime, + @NonNull String start) { + String[] args = + concatenateArrays(new String[] {key, group, consumer, Long.toString(minIdleTime), start}); + return commandManager.submitNewCommand( + XAutoClaim, args, response -> castArray(handleArrayResponse(response), String.class)); + } + + @Override + public CompletableFuture xautoclaim( + @NonNull String key, + @NonNull String group, + @NonNull String consumer, + long minIdleTime, + @NonNull String start, + long count) { + String[] args = + concatenateArrays( + new String[] { + key, group, consumer, Long.toString(minIdleTime), start, Long.toString(count) + }); + return commandManager.submitNewCommand( + XAutoClaim, args, response -> castArray(handleArrayResponse(response), String.class)); + } + + @Override + public CompletableFuture xautoclaimJustId( + @NonNull String key, + @NonNull String group, + @NonNull String consumer, + long minIdleTime, + @NonNull String start) { + String[] args = + concatenateArrays( + new String[] {key, group, consumer, Long.toString(minIdleTime), start, "JUSTID"}); + return commandManager.submitNewCommand( + XAutoClaim, args, response -> castArray(handleArrayResponse(response), String.class)); + } + + @Override + public CompletableFuture xautoclaimJustId( + @NonNull String key, + @NonNull String group, + @NonNull String consumer, + long minIdleTime, + @NonNull String start, + long count) { + String[] args = + concatenateArrays( + new String[] { + key, + group, + consumer, + Long.toString(minIdleTime), + start, + Long.toString(count), + "JUSTID" + }); + return commandManager.submitNewCommand( + XAutoClaim, args, response -> castArray(handleArrayResponse(response), String.class)); + } + @Override public CompletableFuture pttl(@NonNull String key) { return commandManager.submitNewCommand(PTTL, new String[] {key}, this::handleLongResponse); diff --git a/java/client/src/main/java/glide/api/commands/StreamBaseCommands.java b/java/client/src/main/java/glide/api/commands/StreamBaseCommands.java index 07b7627b4d..9b0c1c615d 100644 --- a/java/client/src/main/java/glide/api/commands/StreamBaseCommands.java +++ b/java/client/src/main/java/glide/api/commands/StreamBaseCommands.java @@ -1372,4 +1372,112 @@ CompletableFuture xclaimJustId( */ CompletableFuture[]> xinfoConsumers( GlideString key, GlideString groupName); + + /** + * Transfers ownership of pending stream entries that match the specified criteria. + * + * @see valkey.io for details. + * @param key The key of the stream. + * @param group The consumer group name + * @param consumer The group consumer. + * @param minIdleTime The minimum idle time for the message to be claimed. + * @param start Filters the claimed entries to those that have an ID equal or greater than the + * specified value. + * @return An array containing the following elements: - A stream ID to be used as the start + * argument for the next call to XAUTOCLAIM. This ID is equivalent to the next ID + * in the stream after the entries that were scanned, or "0-0" if the entire stream was + * scanned. - A mapping of the claimed entries, with the keys being the claimed entry IDs and + * the values being a 2D list of the field-value pairs in the format `[[field1, value1], + * [field2, value2], ...]`. - If you are using Redis 7.0.0 or above, the response list will + * also include a list containing the message IDs that were in the Pending Entries List but no + * longer exist in the stream. These IDs are deleted from the Pending Entries List. + * @example + *
+     *      // Redis version < 7.0.0:
+     *      Object[] results = client.xautoclaim("my_stream", "my_group", "my_consumer", 3_600_000L, "0-0").get();
+     * for (Object element: results) {
+     *     System.out.println(element);
+     *
+     *     for (String key: element.get(key)) {
+     *
+     *          for(String entry: ){
+     *             System.out.println(ke);
+     *          }
+     *     }
+     * }
+     *      // Redis version 7.0.0 and above
+     *  
+ */ + CompletableFuture xautoclaim( + String key, String group, String consumer, long minIdleTime, String start); + + /** + * Transfers ownership of pending stream entries that match the specified criteria. + * + * @see valkey.io for details. + * @param key The key of the stream. + * @param group The consumer group name + * @param consumer The group consumer. + * @param minIdleTime The minimum idle time for the message to be claimed. + * @param start Filters the claimed entries to those that have an ID equal or greater than the + * specified value. + * @param count Limits the number of claimed entries to the specified value. + * @return An array containing the following elements: - A stream ID to be used as the start + * argument for the next call to XAUTOCLAIM. This ID is equivalent to the next ID + * in the stream after the entries that were scanned, or "0-0" if the entire stream was + * scanned. - A mapping of the claimed entries, with the keys being the claimed entry IDs and + * the values being a 2D list of the field-value pairs in the format `[[field1, value1], + * [field2, value2], ...]`. - If you are using Redis 7.0.0 or above, the response list will + * also include a list containing the message IDs that were in the Pending Entries List but no + * longer exist in the stream. These IDs are deleted from the Pending Entries List. + */ + CompletableFuture xautoclaim( + String key, String group, String consumer, long minIdleTime, String start, long count); + + /** + * Transfers ownership of pending stream entries that match the specified criteria. This command + * uses the JUSTID argument to further specify that the return value should contain a + * list of claimed IDs without their field-value info. + * + * @see valkey.io for details. + * @param key The key of the stream. + * @param group The consumer group name + * @param consumer The group consumer. + * @param minIdleTime The minimum idle time for the message to be claimed. + * @param start Filters the claimed entries to those that have an ID equal or greater than the + * specified value. + * @return An array containing the following elements: - A stream ID to be used as the start + * argument for the next call to XAUTOCLAIM. This ID is equivalent to the next ID + * in the stream after the entries that were scanned, or "0-0" if the entire stream was + * scanned. - A list of the IDs for the claimed entries. - If you are using Redis 7.0.0 or + * above, the response list will also include a list containing the message IDs that were in + * the Pending Entries List but no longer exist in the stream. These IDs are deleted from the + * Pending Entries List. + */ + CompletableFuture xautoclaimJustId( + String key, String group, String consumer, long minIdleTime, String start); + + /** + * Transfers ownership of pending stream entries that match the specified criteria. This command + * uses the JUSTID argument to further specify that the return value should contain a + * list of claimed IDs without their field-value info. + * + * @see valkey.io for details. + * @param key The key of the stream. + * @param group The consumer group name + * @param consumer The group consumer. + * @param minIdleTime The minimum idle time for the message to be claimed. + * @param start Filters the claimed entries to those that have an ID equal or greater than the + * specified value. + * @param count Limits the number of claimed entries to the specified value. + * @return An array containing the following elements: - A stream ID to be used as the start + * argument for the next call to XAUTOCLAIM. This ID is equivalent to the next ID + * in the stream after the entries that were scanned, or "0-0" if the entire stream was + * scanned. - A list of the IDs for the claimed entries. - If you are using Redis 7.0.0 or + * above, the response list will also include a list containing the message IDs that were in + * the Pending Entries List but no longer exist in the stream. These IDs are deleted from the + * Pending Entries List. + */ + CompletableFuture xautoclaimJustId( + String key, String group, String consumer, long minIdleTime, String start, long count); } 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 cf9698696e..e1252515e3 100644 --- a/java/client/src/main/java/glide/api/models/BaseTransaction.java +++ b/java/client/src/main/java/glide/api/models/BaseTransaction.java @@ -167,6 +167,7 @@ import static redis_request.RedisRequestOuterClass.RequestType.Wait; import static redis_request.RedisRequestOuterClass.RequestType.XAck; import static redis_request.RedisRequestOuterClass.RequestType.XAdd; +import static redis_request.RedisRequestOuterClass.RequestType.XAutoClaim; import static redis_request.RedisRequestOuterClass.RequestType.XClaim; import static redis_request.RedisRequestOuterClass.RequestType.XDel; import static redis_request.RedisRequestOuterClass.RequestType.XGroupCreate; @@ -4083,6 +4084,159 @@ public T xinfoConsumers(@NonNull ArgType key, @NonNull ArgType groupNa return getThis(); } + /** + * Transfers ownership of pending stream entries that match the specified criteria. + * + * @see valkey.io for details. + * @param key The key of the stream. + * @param group The consumer group name + * @param consumer The group consumer. + * @param minIdleTime The minimum idle time for the message to be claimed. + * @param start Filters the claimed entries to those that have an ID equal or greater than the + * specified value. + * @return An array containing the following elements: - A stream ID to be used as the start + * argument for the next call to XAUTOCLAIM. This ID is equivalent to the next ID + * in the stream after the entries that were scanned, or "0-0" if the entire stream was + * scanned. - A mapping of the claimed entries, with the keys being the claimed entry IDs and + * the values being a 2D list of the field-value pairs in the format `[[field1, value1], + * [field2, value2], ...]`. - If you are using Redis 7.0.0 or above, the response list will + * also include a list containing the message IDs that were in the Pending Entries List but no + * longer exist in the stream. These IDs are deleted from the Pending Entries List. + */ + public T xautoclaim( + @NonNull String key, + @NonNull String group, + @NonNull String consumer, + long minIdleTime, + @NonNull String start) { + protobufTransaction.addCommands( + buildCommand( + XAutoClaim, + newArgsBuilder().add(key).add(group).add(consumer).add(minIdleTime).add(start))); + return getThis(); + } + + /** + * Transfers ownership of pending stream entries that match the specified criteria. + * + * @see valkey.io for details. + * @param key The key of the stream. + * @param group The consumer group name + * @param consumer The group consumer. + * @param minIdleTime The minimum idle time for the message to be claimed. + * @param start Filters the claimed entries to those that have an ID equal or greater than the + * specified value. + * @param count Limits the number of claimed entries to the specified value. + * @return An array containing the following elements: - A stream ID to be used as the start + * argument for the next call to XAUTOCLAIM. This ID is equivalent to the next ID + * in the stream after the entries that were scanned, or "0-0" if the entire stream was + * scanned. - A mapping of the claimed entries, with the keys being the claimed entry IDs and + * the values being a 2D list of the field-value pairs in the format `[[field1, value1], + * [field2, value2], ...]`. - If you are using Redis 7.0.0 or above, the response list will + * also include a list containing the message IDs that were in the Pending Entries List but no + * longer exist in the stream. These IDs are deleted from the Pending Entries List. + */ + public T xautoclaim( + @NonNull String key, + @NonNull String group, + @NonNull String consumer, + long minIdleTime, + @NonNull String start, + long count) { + protobufTransaction.addCommands( + buildCommand( + XAutoClaim, + newArgsBuilder() + .add(key) + .add(group) + .add(consumer) + .add(minIdleTime) + .add(start) + .add(count))); + return getThis(); + } + + /** + * Transfers ownership of pending stream entries that match the specified criteria. This command + * uses the JUSTID argument to further specify that the return value should contain a + * list of claimed IDs without their field-value info. + * + * @see valkey.io for details. + * @param key The key of the stream. + * @param group The consumer group name + * @param consumer The group consumer. + * @param minIdleTime The minimum idle time for the message to be claimed. + * @param start Filters the claimed entries to those that have an ID equal or greater than the + * specified value. + * @return An array containing the following elements: - A stream ID to be used as the start + * argument for the next call to XAUTOCLAIM. This ID is equivalent to the next ID + * in the stream after the entries that were scanned, or "0-0" if the entire stream was + * scanned. - A list of the IDs for the claimed entries. - If you are using Redis 7.0.0 or + * above, the response list will also include a list containing the message IDs that were in + * the Pending Entries List but no longer exist in the stream. These IDs are deleted from the + * Pending Entries List. + */ + public T xautoclaimJustId( + @NonNull String key, + @NonNull String group, + @NonNull String consumer, + long minIdleTime, + @NonNull String start) { + protobufTransaction.addCommands( + buildCommand( + XAutoClaim, + newArgsBuilder() + .add(key) + .add(group) + .add(consumer) + .add(minIdleTime) + .add(start) + .add(JUST_ID_REDIS_API))); + return getThis(); + } + + /** + * Transfers ownership of pending stream entries that match the specified criteria. This command + * uses the JUSTID argument to further specify that the return value should contain a + * list of claimed IDs without their field-value info. + * + * @see valkey.io for details. + * @param key The key of the stream. + * @param group The consumer group name + * @param consumer The group consumer. + * @param minIdleTime The minimum idle time for the message to be claimed. + * @param start Filters the claimed entries to those that have an ID equal or greater than the + * specified value. + * @param count Limits the number of claimed entries to the specified value. + * @return An array containing the following elements: - A stream ID to be used as the start + * argument for the next call to XAUTOCLAIM. This ID is equivalent to the next ID + * in the stream after the entries that were scanned, or "0-0" if the entire stream was + * scanned. - A list of the IDs for the claimed entries. - If you are using Redis 7.0.0 or + * above, the response list will also include a list containing the message IDs that were in + * the Pending Entries List but no longer exist in the stream. These IDs are deleted from the + * Pending Entries List. + */ + public T xautoclaimJustId( + @NonNull String key, + @NonNull String group, + @NonNull String consumer, + long minIdleTime, + @NonNull String start, + long count) { + protobufTransaction.addCommands( + buildCommand( + XAutoClaim, + newArgsBuilder() + .add(key) + .add(group) + .add(consumer) + .add(minIdleTime) + .add(start) + .add(count) + .add(JUST_ID_REDIS_API))); + return getThis(); + } + /** * Returns the remaining time to live of key that has a timeout, in milliseconds. * diff --git a/java/client/src/test/java/glide/api/RedisClientTest.java b/java/client/src/test/java/glide/api/RedisClientTest.java index eab5ef4cb4..a9036f4cf9 100644 --- a/java/client/src/test/java/glide/api/RedisClientTest.java +++ b/java/client/src/test/java/glide/api/RedisClientTest.java @@ -234,6 +234,7 @@ import static redis_request.RedisRequestOuterClass.RequestType.Watch; import static redis_request.RedisRequestOuterClass.RequestType.XAck; import static redis_request.RedisRequestOuterClass.RequestType.XAdd; +import static redis_request.RedisRequestOuterClass.RequestType.XAutoClaim; import static redis_request.RedisRequestOuterClass.RequestType.XClaim; import static redis_request.RedisRequestOuterClass.RequestType.XDel; import static redis_request.RedisRequestOuterClass.RequestType.XGroupCreate; @@ -7713,6 +7714,42 @@ public void xclaimJustId_binary_with_options_returns_success() { assertEquals(mockResult, payload); } + @SneakyThrows + @Test + public void xautoclaim() { + // setup + String key = "testKey"; + String groupName = "testGroupName"; + String consumer = "testConsumer"; + Long minIdleTime = 18L; + String start = "0-0"; + + StreamRange end = IdBound.ofExclusive("696969-10"); + String[][] fieldValuesResult = {{"duration", "12345"}, {"event-id", "2"}, {"user-id", "42"}}; + Map completedResult = Map.of(key, fieldValuesResult); + + String[] deletedMessageIds = new String[] {"13-1", "46-2", "89-3"}; + + String[] arguments = concatenateArrays(new String[] {key, groupName, consumer, "18", start}); + Object[] mockResult = new Object[] {start, completedResult, deletedMessageIds}; + + CompletableFuture testResponse = new CompletableFuture<>(); + testResponse.complete(mockResult); + + // match on protobuf request + when(commandManager.submitNewCommand(eq(XAutoClaim), eq(arguments), any())) + .thenReturn(testResponse); + + // exercise + CompletableFuture response = + service.xautoclaim(key, groupName, consumer, minIdleTime, start); + Object[] payload = response.get(); + + // verify + assertEquals(testResponse, response); + assertEquals(mockResult, payload); + } + @SneakyThrows @Test public void xack_binary_returns_success() { From 814bca3e588bd4d58ac5127ba968a0b886c55163 Mon Sep 17 00:00:00 2001 From: Chloe Yip Date: Thu, 4 Jul 2024 12:13:00 -0700 Subject: [PATCH 02/17] add redis client test --- .../test/java/glide/api/RedisClientTest.java | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/java/client/src/test/java/glide/api/RedisClientTest.java b/java/client/src/test/java/glide/api/RedisClientTest.java index a9036f4cf9..002cf10668 100644 --- a/java/client/src/test/java/glide/api/RedisClientTest.java +++ b/java/client/src/test/java/glide/api/RedisClientTest.java @@ -7724,7 +7724,6 @@ public void xautoclaim() { Long minIdleTime = 18L; String start = "0-0"; - StreamRange end = IdBound.ofExclusive("696969-10"); String[][] fieldValuesResult = {{"duration", "12345"}, {"event-id", "2"}, {"user-id", "42"}}; Map completedResult = Map.of(key, fieldValuesResult); @@ -7750,6 +7749,41 @@ public void xautoclaim() { assertEquals(mockResult, payload); } + @SneakyThrows + @Test + public void xautoclaimJustId() { + // setup + String key = "testKey"; + String groupName = "testGroupName"; + String consumer = "testConsumer"; + Long minIdleTime = 18L; + String start = "0-0"; + + String[][] fieldValuesResult = {{"duration", "12345"}, {"event-id", "2"}, {"user-id", "42"}}; + Map completedResult = Map.of(key, fieldValuesResult); + + String[] deletedMessageIds = new String[] {"13-1", "46-2", "89-3"}; + + String[] arguments = concatenateArrays(new String[] {key, groupName, consumer, "18", start, "JUSTID"}); + Object[] mockResult = new Object[] {start, completedResult, deletedMessageIds}; + + CompletableFuture testResponse = new CompletableFuture<>(); + testResponse.complete(mockResult); + + // match on protobuf request + when(commandManager.submitNewCommand(eq(XAutoClaim), eq(arguments), any())) + .thenReturn(testResponse); + + // exercise + CompletableFuture response = + service.xautoclaimJustId(key, groupName, consumer, minIdleTime, start); + Object[] payload = response.get(); + + // verify + assertEquals(testResponse, response); + assertEquals(mockResult, payload); + } + @SneakyThrows @Test public void xack_binary_returns_success() { From ae5a8b42ddc220e465c6a85595b7c74823d3d267 Mon Sep 17 00:00:00 2001 From: Chloe Yip Date: Thu, 4 Jul 2024 14:31:39 -0700 Subject: [PATCH 03/17] add remaining redis client tests --- .../test/java/glide/api/RedisClientTest.java | 76 ++++++++++++++++++- 1 file changed, 74 insertions(+), 2 deletions(-) diff --git a/java/client/src/test/java/glide/api/RedisClientTest.java b/java/client/src/test/java/glide/api/RedisClientTest.java index 002cf10668..153289b392 100644 --- a/java/client/src/test/java/glide/api/RedisClientTest.java +++ b/java/client/src/test/java/glide/api/RedisClientTest.java @@ -7716,7 +7716,7 @@ public void xclaimJustId_binary_with_options_returns_success() { @SneakyThrows @Test - public void xautoclaim() { + public void xautoclaim_return_success() { // setup String key = "testKey"; String groupName = "testGroupName"; @@ -7751,7 +7751,43 @@ public void xautoclaim() { @SneakyThrows @Test - public void xautoclaimJustId() { + public void xautoclaim_with_count_return_success() { + // setup + String key = "testKey"; + String groupName = "testGroupName"; + String consumer = "testConsumer"; + Long minIdleTime = 18L; + String start = "0-0"; + long count = 1234; + + String[][] fieldValuesResult = {{"duration", "12345"}, {"event-id", "2"}, {"user-id", "42"}}; + Map completedResult = Map.of(key, fieldValuesResult); + + String[] deletedMessageIds = new String[] {"13-1", "46-2", "89-3"}; + + String[] arguments = concatenateArrays(new String[] {key, groupName, consumer, "18", start, Long.toString(count)}); + Object[] mockResult = new Object[] {start, completedResult, deletedMessageIds}; + + CompletableFuture testResponse = new CompletableFuture<>(); + testResponse.complete(mockResult); + + // match on protobuf request + when(commandManager.submitNewCommand(eq(XAutoClaim), eq(arguments), any())) + .thenReturn(testResponse); + + // exercise + CompletableFuture response = + service.xautoclaim(key, groupName, consumer, minIdleTime, start, count); + Object[] payload = response.get(); + + // verify + assertEquals(testResponse, response); + assertEquals(mockResult, payload); + } + + @SneakyThrows + @Test + public void xautoclaimJustId_return_success() { // setup String key = "testKey"; String groupName = "testGroupName"; @@ -7784,6 +7820,42 @@ public void xautoclaimJustId() { assertEquals(mockResult, payload); } + @SneakyThrows + @Test + public void xautoclaimJustId_with_count_return_success() { + // setup + String key = "testKey"; + String groupName = "testGroupName"; + String consumer = "testConsumer"; + Long minIdleTime = 18L; + String start = "0-0"; + long count = 1234; + + String[][] fieldValuesResult = {{"duration", "12345"}, {"event-id", "2"}, {"user-id", "42"}}; + Map completedResult = Map.of(key, fieldValuesResult); + + String[] deletedMessageIds = new String[] {"13-1", "46-2", "89-3"}; + + String[] arguments = concatenateArrays(new String[] {key, groupName, consumer, "18", start, Long.toString(1234), "JUSTID"}); + Object[] mockResult = new Object[] {start, completedResult, deletedMessageIds}; + + CompletableFuture testResponse = new CompletableFuture<>(); + testResponse.complete(mockResult); + + // match on protobuf request + when(commandManager.submitNewCommand(eq(XAutoClaim), eq(arguments), any())) + .thenReturn(testResponse); + + // exercise + CompletableFuture response = + service.xautoclaimJustId(key, groupName, consumer, minIdleTime, start, count); + Object[] payload = response.get(); + + // verify + assertEquals(testResponse, response); + assertEquals(mockResult, payload); + } + @SneakyThrows @Test public void xack_binary_returns_success() { From db4ffeab3a8544987b2fff38d30e46b1d0aaddaa Mon Sep 17 00:00:00 2001 From: Chloe Yip Date: Thu, 4 Jul 2024 14:50:06 -0700 Subject: [PATCH 04/17] add transaction tests --- .../test/java/glide/api/RedisClientTest.java | 23 +++++++++++-------- .../glide/api/models/TransactionTests.java | 13 +++++++++++ 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/java/client/src/test/java/glide/api/RedisClientTest.java b/java/client/src/test/java/glide/api/RedisClientTest.java index 153289b392..5ec3bc1a36 100644 --- a/java/client/src/test/java/glide/api/RedisClientTest.java +++ b/java/client/src/test/java/glide/api/RedisClientTest.java @@ -7765,7 +7765,9 @@ public void xautoclaim_with_count_return_success() { String[] deletedMessageIds = new String[] {"13-1", "46-2", "89-3"}; - String[] arguments = concatenateArrays(new String[] {key, groupName, consumer, "18", start, Long.toString(count)}); + String[] arguments = + concatenateArrays( + new String[] {key, groupName, consumer, "18", start, Long.toString(count)}); Object[] mockResult = new Object[] {start, completedResult, deletedMessageIds}; CompletableFuture testResponse = new CompletableFuture<>(); @@ -7773,11 +7775,11 @@ public void xautoclaim_with_count_return_success() { // match on protobuf request when(commandManager.submitNewCommand(eq(XAutoClaim), eq(arguments), any())) - .thenReturn(testResponse); + .thenReturn(testResponse); // exercise CompletableFuture response = - service.xautoclaim(key, groupName, consumer, minIdleTime, start, count); + service.xautoclaim(key, groupName, consumer, minIdleTime, start, count); Object[] payload = response.get(); // verify @@ -7800,7 +7802,8 @@ public void xautoclaimJustId_return_success() { String[] deletedMessageIds = new String[] {"13-1", "46-2", "89-3"}; - String[] arguments = concatenateArrays(new String[] {key, groupName, consumer, "18", start, "JUSTID"}); + String[] arguments = + concatenateArrays(new String[] {key, groupName, consumer, "18", start, "JUSTID"}); Object[] mockResult = new Object[] {start, completedResult, deletedMessageIds}; CompletableFuture testResponse = new CompletableFuture<>(); @@ -7808,11 +7811,11 @@ public void xautoclaimJustId_return_success() { // match on protobuf request when(commandManager.submitNewCommand(eq(XAutoClaim), eq(arguments), any())) - .thenReturn(testResponse); + .thenReturn(testResponse); // exercise CompletableFuture response = - service.xautoclaimJustId(key, groupName, consumer, minIdleTime, start); + service.xautoclaimJustId(key, groupName, consumer, minIdleTime, start); Object[] payload = response.get(); // verify @@ -7836,7 +7839,9 @@ public void xautoclaimJustId_with_count_return_success() { String[] deletedMessageIds = new String[] {"13-1", "46-2", "89-3"}; - String[] arguments = concatenateArrays(new String[] {key, groupName, consumer, "18", start, Long.toString(1234), "JUSTID"}); + String[] arguments = + concatenateArrays( + new String[] {key, groupName, consumer, "18", start, Long.toString(1234), "JUSTID"}); Object[] mockResult = new Object[] {start, completedResult, deletedMessageIds}; CompletableFuture testResponse = new CompletableFuture<>(); @@ -7844,11 +7849,11 @@ public void xautoclaimJustId_with_count_return_success() { // match on protobuf request when(commandManager.submitNewCommand(eq(XAutoClaim), eq(arguments), any())) - .thenReturn(testResponse); + .thenReturn(testResponse); // exercise CompletableFuture response = - service.xautoclaimJustId(key, groupName, consumer, minIdleTime, start, count); + service.xautoclaimJustId(key, groupName, consumer, minIdleTime, start, count); Object[] payload = response.get(); // verify 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 a5ffffd0b8..b2aa158256 100644 --- a/java/client/src/test/java/glide/api/models/TransactionTests.java +++ b/java/client/src/test/java/glide/api/models/TransactionTests.java @@ -193,6 +193,7 @@ import static redis_request.RedisRequestOuterClass.RequestType.Wait; import static redis_request.RedisRequestOuterClass.RequestType.XAck; import static redis_request.RedisRequestOuterClass.RequestType.XAdd; +import static redis_request.RedisRequestOuterClass.RequestType.XAutoClaim; import static redis_request.RedisRequestOuterClass.RequestType.XClaim; import static redis_request.RedisRequestOuterClass.RequestType.XDel; import static redis_request.RedisRequestOuterClass.RequestType.XGroupCreate; @@ -964,6 +965,18 @@ InfScoreBound.NEGATIVE_INFINITY, new ScoreBoundary(3, false), new Limit(1, 2)), transaction.xinfoConsumers("key", "groupName"); results.add(Pair.of(XInfoConsumers, buildArgs("key", "groupName"))); + transaction.xautoclaim("key", "group", "consumer", 99L, "0-0"); + results.add(Pair.of(XAutoClaim, buildArgs("key", "group", "consumer", "99", "0-0"))); + + transaction.xautoclaim("key", "group", "consumer", 99L, "0-0", 1234L); + results.add(Pair.of(XAutoClaim, buildArgs("key", "group", "consumer", "99", "0-0", "1234"))); + + transaction.xautoclaimJustId("key", "group", "consumer", 99L, "0-0"); + results.add(Pair.of(XAutoClaim, buildArgs("key", "group", "consumer", "99", "0-0", "JUSTID"))); + + transaction.xautoclaimJustId("key", "group", "consumer", 99L, "0-0", 1234L); + results.add(Pair.of(XAutoClaim, buildArgs("key", "group", "consumer", "99", "0-0", "1234", "JUSTID"))); + transaction.time(); results.add(Pair.of(Time, buildArgs())); From f675f7a569a2ca17e9b7d8c09370f135d623e660 Mon Sep 17 00:00:00 2001 From: Chloe Yip Date: Thu, 4 Jul 2024 16:15:44 -0700 Subject: [PATCH 05/17] add transaction test utilities --- .../glide/api/models/TransactionTests.java | 3 +- .../java/glide/TransactionTestUtilities.java | 97 ++++++++++++++++++- 2 files changed, 98 insertions(+), 2 deletions(-) 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 b2aa158256..c232655973 100644 --- a/java/client/src/test/java/glide/api/models/TransactionTests.java +++ b/java/client/src/test/java/glide/api/models/TransactionTests.java @@ -975,7 +975,8 @@ InfScoreBound.NEGATIVE_INFINITY, new ScoreBoundary(3, false), new Limit(1, 2)), results.add(Pair.of(XAutoClaim, buildArgs("key", "group", "consumer", "99", "0-0", "JUSTID"))); transaction.xautoclaimJustId("key", "group", "consumer", 99L, "0-0", 1234L); - results.add(Pair.of(XAutoClaim, buildArgs("key", "group", "consumer", "99", "0-0", "1234", "JUSTID"))); + results.add( + Pair.of(XAutoClaim, buildArgs("key", "group", "consumer", "99", "0-0", "1234", "JUSTID"))); transaction.time(); results.add(Pair.of(Time, buildArgs())); diff --git a/java/integTest/src/test/java/glide/TransactionTestUtilities.java b/java/integTest/src/test/java/glide/TransactionTestUtilities.java index 1dcedb4615..893de3d26b 100644 --- a/java/integTest/src/test/java/glide/TransactionTestUtilities.java +++ b/java/integTest/src/test/java/glide/TransactionTestUtilities.java @@ -860,7 +860,20 @@ private static Object[] streamCommands(BaseTransaction transaction) { 0L, new String[] {"0-4"}, StreamClaimOptions.builder().force().build()) - .xpending(streamKey1, groupName1) + .xpending(streamKey1, groupName1); + if (REDIS_VERSION.isGreaterThanOrEqualTo("6.2.0")) { + transaction + .xautoclaim(streamKey1, groupName1, consumer1, 0L, "0-0") + .xautoclaimJustId(streamKey1, groupName1, consumer1, 0L, "0-0"); + + if (REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")) { + transaction + .xautoclaim(streamKey1, groupName1, consumer1, 0L, "0-0") + .xautoclaimJustId(streamKey1, groupName1, consumer1, 0L, "0-0"); + } + } + + transaction .xack(streamKey1, groupName1, new String[] {"0-3"}) .xpending( streamKey1, @@ -936,6 +949,88 @@ private static Object[] streamCommands(BaseTransaction transaction) { OK, // xgroupCreate(streamKey3, groupName3, "0") new Map[] {}, // xinfoGroups(streamKey3) }; + var result = + new Object[] { + "0-1", // xadd(streamKey1, Map.of("field1", "value1"), ... .id("0-1").build()); + "0-2", // xadd(streamKey1, Map.of("field2", "value2"), ... .id("0-2").build()); + "0-3", // xadd(streamKey1, Map.of("field3", "value3"), ... .id("0-3").build()); + 3L, // xlen(streamKey1) + Map.of( + streamKey1, + Map.of("0-3", new String[][] {{"field3", "value3"}})), // xread(Map.of(key9, "0-2")); + Map.of( + streamKey1, + Map.of( + "0-3", + new String[][] {{"field3", "value3"}})), // xread(Map.of(key9, "0-2"), options); + Map.of("0-1", new String[][] {{"field1", "value1"}}), // .xrange(streamKey1, "0-1", "0-1") + Map.of( + "0-1", + new String[][] {{"field1", "value1"}}), // .xrange(streamKey1, "0-1", "0-1", 1l) + Map.of( + "0-1", new String[][] {{"field1", "value1"}}), // .xrevrange(streamKey1, "0-1", "0-1") + Map.of( + "0-1", + new String[][] {{"field1", "value1"}}), // .xrevrange(streamKey1, "0-1", "0-1", 1l) + 1L, // xtrim(streamKey1, new MinId(true, "0-2")) + OK, // xgroupCreate(streamKey1, groupName1, "0-0") + OK, // xgroupCreate(streamKey1, groupName1, "0-0", options) + true, // xgroupCreateConsumer(streamKey1, groupName1, consumer1) + OK, // xgroupSetId(streamKey1, groupName1, "0-2") + Map.of( + streamKey1, + Map.of( + "0-3", + new String[][] { + {"field3", "value3"} + })), // xreadgroup(Map.of(streamKey1, ">"), groupName1, consumer1); + Map.of( + streamKey1, + Map.of()), // xreadgroup(Map.of(streamKey1, ">"), groupName1, consumer1, options); + Map.of(), // xclaim(streamKey1, groupName1, consumer1, 0L, new String[] {"0-1"}) + Map.of( + "0-3", + new String[][] {{"field3", "value3"}}), // xclaim(streamKey1, ..., {"0-3"}, options) + new String[] {"0-3"}, // xclaimJustId(streamKey1, ..., new String[] {"0-3"}) + new String[0], // xclaimJustId(streamKey1, ..., new String[] {"0-4"}, options) + new Object[] { + 1L, "0-3", "0-3", new Object[][] {{consumer1, "1"}} + } // xpending(streamKey1, groupName1) + }; + + if (REDIS_VERSION.isGreaterThanOrEqualTo("6.2.0")) { + result = + concatenateArrays( + new Object[] { + "0-1", Map.of("0-2", new String[][] {{"foo", "bar"}}) + }, // xautoclaim(streamKey1, groupName1, consumer1, 0L, "0-0") + new Object[] { + "0-1", "0-2" + } // xautoclaimJustId(streamKey1, groupName1, consumer1, 0L, "0-0"); + ); + } else if (REDIS_VERSION.isGreaterThanOrEqualTo("6.2.0")) { + result = + concatenateArrays( + new Object[] { + "0-1", Map.of("0-2", new String[][] {{"foo", "bar"}, new String[] {}}) + }, // xautoclaim(streamKey1, groupName1, consumer1, 0L, "0-0") + new Object[] { + "0-1", "0-2", new String[] {} + } // xautoclaimJustId(streamKey1, groupName1, consumer1, 0L, "0-0"); + ); + } + + result = + concatenateArrays( + result, + new Object[] { + 1L, // xack(streamKey1, groupName1, new String[] {"0-3"}) + new Object[] {}, // xpending(streamKey1, groupName1, MIN, MAX, 1L) + 0L, // xgroupDelConsumer(streamKey1, groupName1, consumer1) + true, // xgroupDestroy(streamKey1, groupName1) + true, // xgroupDestroy(streamKey1, groupName2) + 1L // .xdel(streamKey1, new String[] {"0-1", "0-5"}); + }); if (SERVER_VERSION.isGreaterThanOrEqualTo("7.0.0")) { result = From f81df623dc9445db959dad6253474e376624b54f Mon Sep 17 00:00:00 2001 From: Chloe Yip Date: Thu, 4 Jul 2024 16:51:48 -0700 Subject: [PATCH 06/17] fix utitlities --- .../java/glide/TransactionTestUtilities.java | 83 ++++--------------- 1 file changed, 16 insertions(+), 67 deletions(-) diff --git a/java/integTest/src/test/java/glide/TransactionTestUtilities.java b/java/integTest/src/test/java/glide/TransactionTestUtilities.java index 893de3d26b..1ae1629254 100644 --- a/java/integTest/src/test/java/glide/TransactionTestUtilities.java +++ b/java/integTest/src/test/java/glide/TransactionTestUtilities.java @@ -861,6 +861,7 @@ private static Object[] streamCommands(BaseTransaction transaction) { new String[] {"0-4"}, StreamClaimOptions.builder().force().build()) .xpending(streamKey1, groupName1); + if (REDIS_VERSION.isGreaterThanOrEqualTo("6.2.0")) { transaction .xautoclaim(streamKey1, groupName1, consumer1, 0L, "0-0") @@ -896,59 +897,6 @@ private static Object[] streamCommands(BaseTransaction transaction) { .xgroupSetId(streamKey2, groupName3, "1-0", 1); } - Object[] result = { - "0-1", // xadd(streamKey1, Map.of("field1", "value1"), ... .id("0-1").build()); - "0-2", // xadd(streamKey1, Map.of("field2", "value2"), ... .id("0-2").build()); - "0-3", // xadd(streamKey1, Map.of("field3", "value3"), ... .id("0-3").build()); - 3L, // xlen(streamKey1) - Map.of( - streamKey1, - Map.of("0-3", new String[][] {{"field3", "value3"}})), // xread(Map.of(key9, "0-2")); - Map.of( - streamKey1, - Map.of( - "0-3", - new String[][] {{"field3", "value3"}})), // xread(Map.of(key9, "0-2"), options); - Map.of("0-1", new String[][] {{"field1", "value1"}}), // .xrange(streamKey1, "0-1", "0-1") - Map.of("0-1", new String[][] {{"field1", "value1"}}), // .xrange(streamKey1, "0-1", "0-1", 1l) - Map.of("0-1", new String[][] {{"field1", "value1"}}), // .xrevrange(streamKey1, "0-1", "0-1") - Map.of( - "0-1", new String[][] {{"field1", "value1"}}), // .xrevrange(streamKey1, "0-1", "0-1", 1l) - 1L, // xtrim(streamKey1, new MinId(true, "0-2")) - OK, // xgroupCreate(streamKey1, groupName1, "0-0") - new Map[] {}, // .xinfoConsumers(streamKey1, groupName1) - OK, // xgroupCreate(streamKey1, groupName1, "0-0", options) - true, // xgroupCreateConsumer(streamKey1, groupName1, consumer1) - OK, // xgroupSetId(streamKey1, groupName1, "0-2") - Map.of( - streamKey1, - Map.of( - "0-3", - new String[][] { - {"field3", "value3"} - })), // xreadgroup(Map.of(streamKey1, ">"), groupName1, consumer1); - Map.of( - streamKey1, - Map.of()), // xreadgroup(Map.of(streamKey1, ">"), groupName1, consumer1, options); - Map.of(), // xclaim(streamKey1, groupName1, consumer1, 0L, new String[] {"0-1"}) - Map.of( - "0-3", - new String[][] {{"field3", "value3"}}), // xclaim(streamKey1, ..., {"0-3"}, options) - new String[] {"0-3"}, // xclaimJustId(streamKey1, ..., new String[] {"0-3"}) - new String[0], // xclaimJustId(streamKey1, ..., new String[] {"0-4"}, options) - new Object[] { - 1L, "0-3", "0-3", new Object[][] {{consumer1, "1"}} - }, // xpending(streamKey1, groupName1) - 1L, // xack(streamKey1, groupName1, new String[] {"0-3"}) - new Object[] {}, // xpending(streamKey1, groupName1, MIN, MAX, 1L) - 0L, // xgroupDelConsumer(streamKey1, groupName1, consumer1) - true, // xgroupDestroy(streamKey1, groupName1) - true, // xgroupDestroy(streamKey1, groupName2) - 1L, // .xdel(streamKey1, new String[] {"0-1", "0-5"}) - "1-0", // xadd(streamKey3, Map.of("f0", "v0"), id("1-0")) - OK, // xgroupCreate(streamKey3, groupName3, "0") - new Map[] {}, // xinfoGroups(streamKey3) - }; var result = new Object[] { "0-1", // xadd(streamKey1, Map.of("field1", "value1"), ... .id("0-1").build()); @@ -974,6 +922,7 @@ private static Object[] streamCommands(BaseTransaction transaction) { new String[][] {{"field1", "value1"}}), // .xrevrange(streamKey1, "0-1", "0-1", 1l) 1L, // xtrim(streamKey1, new MinId(true, "0-2")) OK, // xgroupCreate(streamKey1, groupName1, "0-0") + new Map[] {}, // .xinfoConsumers(streamKey1, groupName1) OK, // xgroupCreate(streamKey1, groupName1, "0-0", options) true, // xgroupCreateConsumer(streamKey1, groupName1, consumer1) OK, // xgroupSetId(streamKey1, groupName1, "0-2") @@ -994,32 +943,29 @@ private static Object[] streamCommands(BaseTransaction transaction) { new String[] {"0-3"}, // xclaimJustId(streamKey1, ..., new String[] {"0-3"}) new String[0], // xclaimJustId(streamKey1, ..., new String[] {"0-4"}, options) new Object[] { - 1L, "0-3", "0-3", new Object[][] {{consumer1, "1"}} - } // xpending(streamKey1, groupName1) + 1L, "0-3", "0-3", new Object[][] {{consumer1, "1"}} // xpending(streamKey1, groupName1) + } }; - if (REDIS_VERSION.isGreaterThanOrEqualTo("6.2.0")) { result = concatenateArrays( + result, new Object[] { - "0-1", Map.of("0-2", new String[][] {{"foo", "bar"}}) - }, // xautoclaim(streamKey1, groupName1, consumer1, 0L, "0-0") - new Object[] { - "0-1", "0-2" + Map.of("0-1", Map.of("0-3", new String[][] {{"field3", "value3"}})), + "0-1", "0-3" } // xautoclaimJustId(streamKey1, groupName1, consumer1, 0L, "0-0"); ); - } else if (REDIS_VERSION.isGreaterThanOrEqualTo("6.2.0")) { + } else if (REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")) { result = concatenateArrays( + result, new Object[] { - "0-1", Map.of("0-2", new String[][] {{"foo", "bar"}, new String[] {}}) - }, // xautoclaim(streamKey1, groupName1, consumer1, 0L, "0-0") - new Object[] { - "0-1", "0-2", new String[] {} + "0-0", Map.of("0-3", new String[][] {{"field3", "value3"}, new String[] {}}) + , // xautoclaim(streamKey1, groupName1, consumer1, 0L, "0-0") + "0-1", "0-3", new String[] {} } // xautoclaimJustId(streamKey1, groupName1, consumer1, 0L, "0-0"); ); } - result = concatenateArrays( result, @@ -1029,7 +975,10 @@ private static Object[] streamCommands(BaseTransaction transaction) { 0L, // xgroupDelConsumer(streamKey1, groupName1, consumer1) true, // xgroupDestroy(streamKey1, groupName1) true, // xgroupDestroy(streamKey1, groupName2) - 1L // .xdel(streamKey1, new String[] {"0-1", "0-5"}); + 1L, // .xdel(streamKey1, new String[] {"0-1", "0-5"}) + "1-0", // xadd(streamKey3, Map.of("f0", "v0"), id("1-0")) + OK, // xgroupCreate(streamKey3, groupName3, "0") + new Map[] {} // xinfoGroups(streamKey3) }); if (SERVER_VERSION.isGreaterThanOrEqualTo("7.0.0")) { From d7d804cb1a1b6bb1225173ada0d7c211305d9e6a Mon Sep 17 00:00:00 2001 From: jamesx-improving Date: Thu, 4 Jul 2024 20:59:02 -0700 Subject: [PATCH 07/17] add GlideString support --- .../src/main/java/glide/api/BaseClient.java | 64 ++++++- .../api/commands/StreamBaseCommands.java | 108 ++++++++++++ .../test/java/glide/api/RedisClientTest.java | 157 +++++++++++++++++- 3 files changed, 323 insertions(+), 6 deletions(-) diff --git a/java/client/src/main/java/glide/api/BaseClient.java b/java/client/src/main/java/glide/api/BaseClient.java index 3f8b40fb0c..30d62063a5 100644 --- a/java/client/src/main/java/glide/api/BaseClient.java +++ b/java/client/src/main/java/glide/api/BaseClient.java @@ -2808,6 +2808,18 @@ public CompletableFuture xautoclaim( XAutoClaim, args, response -> castArray(handleArrayResponse(response), String.class)); } + @Override + public CompletableFuture xautoclaim( + @NonNull GlideString key, + @NonNull GlideString group, + @NonNull GlideString consumer, + long minIdleTime, + @NonNull GlideString start) { + GlideString[] args = new GlideString[] {key, group, consumer, gs(Long.toString(minIdleTime)), start}; + return commandManager.submitNewCommand( + XAutoClaim, args, this::handleArrayResponse); + } + @Override public CompletableFuture xautoclaim( @NonNull String key, @@ -2819,12 +2831,27 @@ public CompletableFuture xautoclaim( String[] args = concatenateArrays( new String[] { - key, group, consumer, Long.toString(minIdleTime), start, Long.toString(count) + key, group, consumer, Long.toString(minIdleTime), start, "COUNT", Long.toString(count) }); return commandManager.submitNewCommand( XAutoClaim, args, response -> castArray(handleArrayResponse(response), String.class)); } + @Override + public CompletableFuture xautoclaim( + @NonNull GlideString key, + @NonNull GlideString group, + @NonNull GlideString consumer, + long minIdleTime, + @NonNull GlideString start, + long count) { + GlideString[] args = new GlideString[] { + key, group, consumer, gs(Long.toString(minIdleTime)), start, gs("COUNT"), gs(Long.toString(count)) + }; + return commandManager.submitNewCommand( + XAutoClaim, args, this::handleArrayResponse); + } + @Override public CompletableFuture xautoclaimJustId( @NonNull String key, @@ -2839,6 +2866,18 @@ public CompletableFuture xautoclaimJustId( XAutoClaim, args, response -> castArray(handleArrayResponse(response), String.class)); } + @Override + public CompletableFuture xautoclaimJustId( + @NonNull GlideString key, + @NonNull GlideString group, + @NonNull GlideString consumer, + long minIdleTime, + @NonNull GlideString start) { + GlideString[] args = new GlideString[] {key, group, consumer, gs(Long.toString(minIdleTime)), start, gs("JUSTID")}; + return commandManager.submitNewCommand( + XAutoClaim, args, this::handleArrayResponse); + } + @Override public CompletableFuture xautoclaimJustId( @NonNull String key, @@ -2855,6 +2894,7 @@ public CompletableFuture xautoclaimJustId( consumer, Long.toString(minIdleTime), start, + "COUNT", Long.toString(count), "JUSTID" }); @@ -2862,6 +2902,28 @@ public CompletableFuture xautoclaimJustId( XAutoClaim, args, response -> castArray(handleArrayResponse(response), String.class)); } + @Override + public CompletableFuture xautoclaimJustId( + @NonNull GlideString key, + @NonNull GlideString group, + @NonNull GlideString consumer, + long minIdleTime, + @NonNull GlideString start, + long count) { + GlideString[] args = new GlideString[] { + key, + group, + consumer, + gs(Long.toString(minIdleTime)), + start, + gs("COUNT"), + gs(Long.toString(count)), + gs("JUSTID") + }; + return commandManager.submitNewCommand( + XAutoClaim, args, this::handleArrayResponse); + } + @Override public CompletableFuture pttl(@NonNull String key) { return commandManager.submitNewCommand(PTTL, new String[] {key}, this::handleLongResponse); diff --git a/java/client/src/main/java/glide/api/commands/StreamBaseCommands.java b/java/client/src/main/java/glide/api/commands/StreamBaseCommands.java index 9b0c1c615d..3bb2639cff 100644 --- a/java/client/src/main/java/glide/api/commands/StreamBaseCommands.java +++ b/java/client/src/main/java/glide/api/commands/StreamBaseCommands.java @@ -1411,6 +1411,44 @@ CompletableFuture[]> xinfoConsumers( CompletableFuture xautoclaim( String key, String group, String consumer, long minIdleTime, String start); + /** + * Transfers ownership of pending stream entries that match the specified criteria. + * + * @see valkey.io for details. + * @param key The key of the stream. + * @param group The consumer group name + * @param consumer The group consumer. + * @param minIdleTime The minimum idle time for the message to be claimed. + * @param start Filters the claimed entries to those that have an ID equal or greater than the + * specified value. + * @return An array containing the following elements: - A stream ID to be used as the start + * argument for the next call to XAUTOCLAIM. This ID is equivalent to the next ID + * in the stream after the entries that were scanned, or "0-0" if the entire stream was + * scanned. - A mapping of the claimed entries, with the keys being the claimed entry IDs and + * the values being a 2D list of the field-value pairs in the format `[[field1, value1], + * [field2, value2], ...]`. - If you are using Redis 7.0.0 or above, the response list will + * also include a list containing the message IDs that were in the Pending Entries List but no + * longer exist in the stream. These IDs are deleted from the Pending Entries List. + * @example + *
+     *      // Redis version < 7.0.0:
+     *      Object[] results = client.xautoclaim("my_stream", "my_group", "my_consumer", 3_600_000L, "0-0").get();
+     * for (Object element: results) {
+     *     System.out.println(element);
+     *
+     *     for (String key: element.get(key)) {
+     *
+     *          for(String entry: ){
+     *             System.out.println(ke);
+     *          }
+     *     }
+     * }
+     *      // Redis version 7.0.0 and above
+     *  
+ */ + CompletableFuture xautoclaim( + GlideString key, GlideString group, GlideString consumer, long minIdleTime, GlideString start); + /** * Transfers ownership of pending stream entries that match the specified criteria. * @@ -1434,6 +1472,29 @@ CompletableFuture xautoclaim( CompletableFuture xautoclaim( String key, String group, String consumer, long minIdleTime, String start, long count); + /** + * Transfers ownership of pending stream entries that match the specified criteria. + * + * @see valkey.io for details. + * @param key The key of the stream. + * @param group The consumer group name + * @param consumer The group consumer. + * @param minIdleTime The minimum idle time for the message to be claimed. + * @param start Filters the claimed entries to those that have an ID equal or greater than the + * specified value. + * @param count Limits the number of claimed entries to the specified value. + * @return An array containing the following elements: - A stream ID to be used as the start + * argument for the next call to XAUTOCLAIM. This ID is equivalent to the next ID + * in the stream after the entries that were scanned, or "0-0" if the entire stream was + * scanned. - A mapping of the claimed entries, with the keys being the claimed entry IDs and + * the values being a 2D list of the field-value pairs in the format `[[field1, value1], + * [field2, value2], ...]`. - If you are using Redis 7.0.0 or above, the response list will + * also include a list containing the message IDs that were in the Pending Entries List but no + * longer exist in the stream. These IDs are deleted from the Pending Entries List. + */ + CompletableFuture xautoclaim( + GlideString key, GlideString group, GlideString consumer, long minIdleTime, GlideString start, long count); + /** * Transfers ownership of pending stream entries that match the specified criteria. This command * uses the JUSTID argument to further specify that the return value should contain a @@ -1457,6 +1518,29 @@ CompletableFuture xautoclaim( CompletableFuture xautoclaimJustId( String key, String group, String consumer, long minIdleTime, String start); + /** + * Transfers ownership of pending stream entries that match the specified criteria. This command + * uses the JUSTID argument to further specify that the return value should contain a + * list of claimed IDs without their field-value info. + * + * @see valkey.io for details. + * @param key The key of the stream. + * @param group The consumer group name + * @param consumer The group consumer. + * @param minIdleTime The minimum idle time for the message to be claimed. + * @param start Filters the claimed entries to those that have an ID equal or greater than the + * specified value. + * @return An array containing the following elements: - A stream ID to be used as the start + * argument for the next call to XAUTOCLAIM. This ID is equivalent to the next ID + * in the stream after the entries that were scanned, or "0-0" if the entire stream was + * scanned. - A list of the IDs for the claimed entries. - If you are using Redis 7.0.0 or + * above, the response list will also include a list containing the message IDs that were in + * the Pending Entries List but no longer exist in the stream. These IDs are deleted from the + * Pending Entries List. + */ + CompletableFuture xautoclaimJustId( + GlideString key, GlideString group, GlideString consumer, long minIdleTime, GlideString start); + /** * Transfers ownership of pending stream entries that match the specified criteria. This command * uses the JUSTID argument to further specify that the return value should contain a @@ -1480,4 +1564,28 @@ CompletableFuture xautoclaimJustId( */ CompletableFuture xautoclaimJustId( String key, String group, String consumer, long minIdleTime, String start, long count); + + /** + * Transfers ownership of pending stream entries that match the specified criteria. This command + * uses the JUSTID argument to further specify that the return value should contain a + * list of claimed IDs without their field-value info. + * + * @see valkey.io for details. + * @param key The key of the stream. + * @param group The consumer group name + * @param consumer The group consumer. + * @param minIdleTime The minimum idle time for the message to be claimed. + * @param start Filters the claimed entries to those that have an ID equal or greater than the + * specified value. + * @param count Limits the number of claimed entries to the specified value. + * @return An array containing the following elements: - A stream ID to be used as the start + * argument for the next call to XAUTOCLAIM. This ID is equivalent to the next ID + * in the stream after the entries that were scanned, or "0-0" if the entire stream was + * scanned. - A list of the IDs for the claimed entries. - If you are using Redis 7.0.0 or + * above, the response list will also include a list containing the message IDs that were in + * the Pending Entries List but no longer exist in the stream. These IDs are deleted from the + * Pending Entries List. + */ + CompletableFuture xautoclaimJustId( + GlideString key, GlideString group, GlideString consumer, long minIdleTime, GlideString start, long count); } diff --git a/java/client/src/test/java/glide/api/RedisClientTest.java b/java/client/src/test/java/glide/api/RedisClientTest.java index 5ec3bc1a36..34653ff81e 100644 --- a/java/client/src/test/java/glide/api/RedisClientTest.java +++ b/java/client/src/test/java/glide/api/RedisClientTest.java @@ -7749,6 +7749,41 @@ public void xautoclaim_return_success() { assertEquals(mockResult, payload); } + @SneakyThrows + @Test + public void xautoclaim_binary_return_success() { + // setup + GlideString key = gs("testKey"); + GlideString groupName = gs("testGroupName"); + GlideString consumer = gs("testConsumer"); + Long minIdleTime = 18L; + GlideString start = gs("0-0"); + + GlideString[][] fieldValuesResult = {{gs("duration"), gs("12345")}, {gs("event-id"), gs("2")}, {gs("user-id"), gs("42")}}; + Map completedResult = Map.of(key, fieldValuesResult); + + GlideString[] deletedMessageIds = new GlideString[] {gs("13-1"), gs("46-2"), gs("89-3")}; + + GlideString[] arguments = concatenateArrays(new GlideString[] {key, groupName, consumer, gs("18"), start}); + Object[] mockResult = new Object[] {start, completedResult, deletedMessageIds}; + + CompletableFuture testResponse = new CompletableFuture<>(); + testResponse.complete(mockResult); + + // match on protobuf request + when(commandManager.submitNewCommand(eq(XAutoClaim), eq(arguments), any())) + .thenReturn(testResponse); + + // exercise + CompletableFuture response = + service.xautoclaim(key, groupName, consumer, minIdleTime, start); + Object[] payload = response.get(); + + // verify + assertEquals(testResponse, response); + assertEquals(mockResult, payload); + } + @SneakyThrows @Test public void xautoclaim_with_count_return_success() { @@ -7767,7 +7802,7 @@ public void xautoclaim_with_count_return_success() { String[] arguments = concatenateArrays( - new String[] {key, groupName, consumer, "18", start, Long.toString(count)}); + new String[] {key, groupName, consumer, "18", start, "COUNT", Long.toString(count)}); Object[] mockResult = new Object[] {start, completedResult, deletedMessageIds}; CompletableFuture testResponse = new CompletableFuture<>(); @@ -7787,6 +7822,44 @@ public void xautoclaim_with_count_return_success() { assertEquals(mockResult, payload); } + @SneakyThrows + @Test + public void xautoclaim_binary_with_count_return_success() { + // setup + GlideString key = gs("testKey"); + GlideString groupName = gs("testGroupName"); + GlideString consumer = gs("testConsumer"); + Long minIdleTime = 18L; + GlideString start = gs("0-0"); + long count = 1234; + + GlideString[][] fieldValuesResult = {{gs("duration"), gs("12345")}, {gs("event-id"), gs("2")}, {gs("user-id"), gs("42")}}; + Map completedResult = Map.of(key, fieldValuesResult); + + GlideString[] deletedMessageIds = new GlideString[] {gs("13-1"), gs("46-2"), gs("89-3")}; + + GlideString[] arguments = + concatenateArrays( + new GlideString[] {key, groupName, consumer, gs("18"), start, gs("COUNT"), gs(Long.toString(count))}); + Object[] mockResult = new Object[] {start, completedResult, deletedMessageIds}; + + CompletableFuture testResponse = new CompletableFuture<>(); + testResponse.complete(mockResult); + + // match on protobuf request + when(commandManager.submitNewCommand(eq(XAutoClaim), eq(arguments), any())) + .thenReturn(testResponse); + + // exercise + CompletableFuture response = + service.xautoclaim(key, groupName, consumer, minIdleTime, start, count); + Object[] payload = response.get(); + + // verify + assertEquals(testResponse, response); + assertEquals(mockResult, payload); + } + @SneakyThrows @Test public void xautoclaimJustId_return_success() { @@ -7823,6 +7896,42 @@ public void xautoclaimJustId_return_success() { assertEquals(mockResult, payload); } + @SneakyThrows + @Test + public void xautoclaimJustId_binary_return_success() { + // setup + GlideString key = gs("testKey"); + GlideString groupName = gs("testGroupName"); + GlideString consumer = gs("testConsumer"); + Long minIdleTime = 18L; + GlideString start = gs("0-0"); + + GlideString[][] fieldValuesResult = {{gs("duration"), gs("12345")}, {gs("event-id"), gs("2")}, {gs("user-id"), gs("42")}}; + Map completedResult = Map.of(key, fieldValuesResult); + + GlideString[] deletedMessageIds = new GlideString[] {gs("13-1"), gs("46-2"), gs("89-3")}; + + GlideString[] arguments = + concatenateArrays(new GlideString[] {key, groupName, consumer, gs("18"), start, gs("JUSTID")}); + Object[] mockResult = new Object[] {start, completedResult, deletedMessageIds}; + + CompletableFuture testResponse = new CompletableFuture<>(); + testResponse.complete(mockResult); + + // match on protobuf request + when(commandManager.submitNewCommand(eq(XAutoClaim), eq(arguments), any())) + .thenReturn(testResponse); + + // exercise + CompletableFuture response = + service.xautoclaimJustId(key, groupName, consumer, minIdleTime, start); + Object[] payload = response.get(); + + // verify + assertEquals(testResponse, response); + assertEquals(mockResult, payload); + } + @SneakyThrows @Test public void xautoclaimJustId_with_count_return_success() { @@ -7840,8 +7949,8 @@ public void xautoclaimJustId_with_count_return_success() { String[] deletedMessageIds = new String[] {"13-1", "46-2", "89-3"}; String[] arguments = - concatenateArrays( - new String[] {key, groupName, consumer, "18", start, Long.toString(1234), "JUSTID"}); + concatenateArrays( + new String[] {key, groupName, consumer, Long.toString(minIdleTime), start, "COUNT", Long.toString(count), "JUSTID"}); Object[] mockResult = new Object[] {start, completedResult, deletedMessageIds}; CompletableFuture testResponse = new CompletableFuture<>(); @@ -7849,11 +7958,49 @@ public void xautoclaimJustId_with_count_return_success() { // match on protobuf request when(commandManager.submitNewCommand(eq(XAutoClaim), eq(arguments), any())) - .thenReturn(testResponse); + .thenReturn(testResponse); + + // exercise + CompletableFuture response = + service.xautoclaimJustId(key, groupName, consumer, minIdleTime, start, count); + Object[] payload = response.get(); + + // verify + assertEquals(testResponse, response); + assertEquals(mockResult, payload); + } + + @SneakyThrows + @Test + public void xautoclaimJustId_binary_with_count_return_success() { + // setup + GlideString key = gs("testKey"); + GlideString groupName = gs("testGroupName"); + GlideString consumer = gs("testConsumer"); + Long minIdleTime = 18L; + GlideString start = gs("0-0"); + long count = 1234; + + GlideString[][] fieldValuesResult = {{gs("duration"), gs("12345")}, {gs("event-id"), gs("2")}, {gs("user-id"), gs("42")}}; + Map completedResult = Map.of(key, fieldValuesResult); + + GlideString[] deletedMessageIds = new GlideString[] {gs("13-1"), gs("46-2"), gs("89-3")}; + + GlideString[] arguments = + concatenateArrays( + new GlideString[] {key, groupName, consumer, gs(Long.toString(minIdleTime)), start, gs("COUNT"), gs(Long.toString(count)), gs("JUSTID")}); + Object[] mockResult = new Object[] {start, completedResult, deletedMessageIds}; + + CompletableFuture testResponse = new CompletableFuture<>(); + testResponse.complete(mockResult); + + // match on protobuf request + when(commandManager.submitNewCommand(eq(XAutoClaim), eq(arguments), any())) + .thenReturn(testResponse); // exercise CompletableFuture response = - service.xautoclaimJustId(key, groupName, consumer, minIdleTime, start, count); + service.xautoclaimJustId(key, groupName, consumer, minIdleTime, start, count); Object[] payload = response.get(); // verify From 95b58738663701f473c3b92e95562ed26dfedae0 Mon Sep 17 00:00:00 2001 From: jamesx-improving Date: Thu, 4 Jul 2024 15:30:50 -0700 Subject: [PATCH 08/17] SharedCommandTest and minor fixes --- .../src/main/java/glide/api/BaseClient.java | 27 +++--- .../test/java/glide/SharedCommandTests.java | 83 +++++++++++++++++++ 2 files changed, 93 insertions(+), 17 deletions(-) diff --git a/java/client/src/main/java/glide/api/BaseClient.java b/java/client/src/main/java/glide/api/BaseClient.java index 30d62063a5..5054396c71 100644 --- a/java/client/src/main/java/glide/api/BaseClient.java +++ b/java/client/src/main/java/glide/api/BaseClient.java @@ -2802,10 +2802,9 @@ public CompletableFuture xautoclaim( @NonNull String consumer, long minIdleTime, @NonNull String start) { - String[] args = - concatenateArrays(new String[] {key, group, consumer, Long.toString(minIdleTime), start}); + String[] args = new String[] {key, group, consumer, Long.toString(minIdleTime), start}; return commandManager.submitNewCommand( - XAutoClaim, args, response -> castArray(handleArrayResponse(response), String.class)); + XAutoClaim, args, this::handleArrayResponse); } @Override @@ -2828,13 +2827,11 @@ public CompletableFuture xautoclaim( long minIdleTime, @NonNull String start, long count) { - String[] args = - concatenateArrays( - new String[] { + String[] args = new String[] { key, group, consumer, Long.toString(minIdleTime), start, "COUNT", Long.toString(count) - }); + }; return commandManager.submitNewCommand( - XAutoClaim, args, response -> castArray(handleArrayResponse(response), String.class)); + XAutoClaim, args, this::handleArrayResponse); } @Override @@ -2859,11 +2856,9 @@ public CompletableFuture xautoclaimJustId( @NonNull String consumer, long minIdleTime, @NonNull String start) { - String[] args = - concatenateArrays( - new String[] {key, group, consumer, Long.toString(minIdleTime), start, "JUSTID"}); + String[] args = new String[] {key, group, consumer, Long.toString(minIdleTime), start, "JUSTID"}; return commandManager.submitNewCommand( - XAutoClaim, args, response -> castArray(handleArrayResponse(response), String.class)); + XAutoClaim, args, this::handleArrayResponse); } @Override @@ -2886,9 +2881,7 @@ public CompletableFuture xautoclaimJustId( long minIdleTime, @NonNull String start, long count) { - String[] args = - concatenateArrays( - new String[] { + String[] args = new String[] { key, group, consumer, @@ -2897,9 +2890,9 @@ public CompletableFuture xautoclaimJustId( "COUNT", Long.toString(count), "JUSTID" - }); + }; return commandManager.submitNewCommand( - XAutoClaim, args, response -> castArray(handleArrayResponse(response), String.class)); + XAutoClaim, args, this::handleArrayResponse); } @Override diff --git a/java/integTest/src/test/java/glide/SharedCommandTests.java b/java/integTest/src/test/java/glide/SharedCommandTests.java index 76d754e7a5..0a830d16c3 100644 --- a/java/integTest/src/test/java/glide/SharedCommandTests.java +++ b/java/integTest/src/test/java/glide/SharedCommandTests.java @@ -7116,6 +7116,89 @@ public void xclaim_return_failures(BaseClient client) { // assertInstanceOf(RequestException.class, executionException.getCause()); // } + @SneakyThrows + @ParameterizedTest(autoCloseArguments = false) + @MethodSource("getClients") + public void xautoclaim(BaseClient client) { + String minVersion = "6.2.0"; + assumeTrue(REDIS_VERSION.isGreaterThanOrEqualTo(minVersion), "This feature added in redis " + minVersion); + boolean isVersion7OrAbove = REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0"); + String key = UUID.randomUUID().toString(); + String groupName = UUID.randomUUID().toString(); + String zeroStreamId = "0-0"; + String consumer = UUID.randomUUID().toString(); + + // Add 4 stream entries for consumer + String streamid_0 = client.xadd(key, Map.of("f1", "v1"/*, "f2", "v2"*/)).get(); + assertNotNull(streamid_0); + String streamid_1 = client.xadd(key, Map.of("field1", "value1")).get(); + assertNotNull(streamid_1); + String streamid_2 = client.xadd(key, Map.of("field2", "value2")).get(); + assertNotNull(streamid_2); + String streamid_3 = client.xadd(key, Map.of("field3", "value3")).get(); + assertNotNull(streamid_3); + + // create group and consumer for the group + assertEquals( + OK, + client + .xgroupCreate( + key, groupName, zeroStreamId, StreamGroupOptions.builder().makeStream().build()) + .get()); + + // read the entire stream for the consumer and mark messages as pending + var xreadgroup_result = client.xreadgroup(Map.of(key, ">"), groupName, consumer).get(); + assertDeepEquals( + Map.of( + key, + Map.of( + streamid_0, new String[][] {{"f1", "v1"}/*, {"f2", "v2"}*/}, + streamid_1, new String[][] {{"field1", "value1"}}, + streamid_2, new String[][] {{"field2", "value2"}}, + streamid_3, new String[][] {{"field3", "value3"}})), + xreadgroup_result); + + Object[] xautoclaimResult1 = client.xautoclaim(key, groupName, consumer, 0L, zeroStreamId, 1L).get(); + assertEquals(streamid_1, xautoclaimResult1[0]); + assertDeepEquals(Map.of(streamid_0, new String[][] {{"f1", "v1"}/*, {"f2", "v2"}*/}), xautoclaimResult1[1]); + + // if using Redis 7.0.0 or above, responses also include a list of entry IDs that were removed from the Pending + // Entries List because they no longer exist in the stream + if (REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")) { + assertDeepEquals(new Object[]{}, xautoclaimResult1[2]); + } + + // delete entry 1-2 + assertEquals(1, client.xdel(key, new String[] {streamid_2}).get()); + + // autoclaim the rest of the entries + Object[] xautoclaimResult2 = client.xautoclaim(key, groupName, consumer, 0L, streamid_1).get(); + assertEquals(zeroStreamId, xautoclaimResult2[0]); // "0-0" is returned to indicate the entire stream was scanned. + assertDeepEquals(Map.of( + streamid_1, new String[][] {{"field1", "value1"}}, + streamid_3, new String[][] {{"field3", "value3"}} + ), + xautoclaimResult2[1] + ); + if (REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")) { + assertDeepEquals(new String[]{streamid_2}, xautoclaimResult2[2]); + } + + // autoclaim with JUSTID: result at index 1 does not contain fields/values of the claimed entries, only IDs + Object[] justIdResult = client.xautoclaimJustId(key, groupName, consumer, 0L, zeroStreamId).get(); + assertEquals(zeroStreamId, justIdResult[0]); + if (REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")) { + assertDeepEquals(new String[] {streamid_0, streamid_1, streamid_3}, justIdResult[1]); + assertDeepEquals(new Object[] {}, justIdResult[2]); + } + else { + // in Redis < 7.0.0, specifically for XAUTOCLAIM with JUSTID, entry IDs that were in the Pending Entries List + // but are no longer in the stream still show up in the response + assertDeepEquals(new String[] {streamid_0, streamid_1, streamid_2, streamid_3}, justIdResult[1]); + } + + } + @SneakyThrows @ParameterizedTest(autoCloseArguments = false) @MethodSource("getClients") From ba3bff949e249f2fbd71afb68c655db5ed9a7375 Mon Sep 17 00:00:00 2001 From: jamesx-improving Date: Fri, 5 Jul 2024 01:16:44 -0700 Subject: [PATCH 09/17] fix BaseTransaction and TransactionTests --- .../src/main/java/glide/api/models/BaseTransaction.java | 2 ++ .../src/test/java/glide/api/models/TransactionTests.java | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) 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 e1252515e3..21e7b33e3d 100644 --- a/java/client/src/main/java/glide/api/models/BaseTransaction.java +++ b/java/client/src/main/java/glide/api/models/BaseTransaction.java @@ -4152,6 +4152,7 @@ public T xautoclaim( .add(consumer) .add(minIdleTime) .add(start) + .add("COUNT") .add(count))); return getThis(); } @@ -4232,6 +4233,7 @@ public T xautoclaimJustId( .add(consumer) .add(minIdleTime) .add(start) + .add("COUNT") .add(count) .add(JUST_ID_REDIS_API))); return getThis(); 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 c232655973..8a0dff6a4e 100644 --- a/java/client/src/test/java/glide/api/models/TransactionTests.java +++ b/java/client/src/test/java/glide/api/models/TransactionTests.java @@ -969,14 +969,14 @@ InfScoreBound.NEGATIVE_INFINITY, new ScoreBoundary(3, false), new Limit(1, 2)), results.add(Pair.of(XAutoClaim, buildArgs("key", "group", "consumer", "99", "0-0"))); transaction.xautoclaim("key", "group", "consumer", 99L, "0-0", 1234L); - results.add(Pair.of(XAutoClaim, buildArgs("key", "group", "consumer", "99", "0-0", "1234"))); + results.add(Pair.of(XAutoClaim, buildArgs("key", "group", "consumer", "99", "0-0", "COUNT", "1234"))); transaction.xautoclaimJustId("key", "group", "consumer", 99L, "0-0"); results.add(Pair.of(XAutoClaim, buildArgs("key", "group", "consumer", "99", "0-0", "JUSTID"))); transaction.xautoclaimJustId("key", "group", "consumer", 99L, "0-0", 1234L); results.add( - Pair.of(XAutoClaim, buildArgs("key", "group", "consumer", "99", "0-0", "1234", "JUSTID"))); + Pair.of(XAutoClaim, buildArgs("key", "group", "consumer", "99", "0-0", "COUNT", "1234", "JUSTID"))); transaction.time(); results.add(Pair.of(Time, buildArgs())); From 2b3fb6dfec2f741636f6b22f9b847f5a7147f139 Mon Sep 17 00:00:00 2001 From: jamesx-improving Date: Fri, 5 Jul 2024 11:49:02 -0700 Subject: [PATCH 10/17] fix TransactionTestUtilities --- .../java/glide/TransactionTestUtilities.java | 47 ++++++++++--------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/java/integTest/src/test/java/glide/TransactionTestUtilities.java b/java/integTest/src/test/java/glide/TransactionTestUtilities.java index 1ae1629254..ae2d88f5b1 100644 --- a/java/integTest/src/test/java/glide/TransactionTestUtilities.java +++ b/java/integTest/src/test/java/glide/TransactionTestUtilities.java @@ -866,12 +866,6 @@ private static Object[] streamCommands(BaseTransaction transaction) { transaction .xautoclaim(streamKey1, groupName1, consumer1, 0L, "0-0") .xautoclaimJustId(streamKey1, groupName1, consumer1, 0L, "0-0"); - - if (REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")) { - transaction - .xautoclaim(streamKey1, groupName1, consumer1, 0L, "0-0") - .xautoclaimJustId(streamKey1, groupName1, consumer1, 0L, "0-0"); - } } transaction @@ -946,25 +940,32 @@ private static Object[] streamCommands(BaseTransaction transaction) { 1L, "0-3", "0-3", new Object[][] {{consumer1, "1"}} // xpending(streamKey1, groupName1) } }; - if (REDIS_VERSION.isGreaterThanOrEqualTo("6.2.0")) { + if (REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")) { result = - concatenateArrays( - result, - new Object[] { - Map.of("0-1", Map.of("0-3", new String[][] {{"field3", "value3"}})), - "0-1", "0-3" - } // xautoclaimJustId(streamKey1, groupName1, consumer1, 0L, "0-0"); - ); - } else if (REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")) { + concatenateArrays( + result, + new Object[] { + new Object[]{ + "0-0", + Map.of("0-3", new String[][]{{"field3", "value3"}}), + new Object[]{} + }, // xautoclaim(streamKey1, groupName1, consumer1, 0L, "0-0") + new Object[] {"0-0", new String[]{"0-3"}, new Object[] {} } // xautoclaimJustId(streamKey1, groupName1, consumer1, 0L, "0-0"); + } + ); + } + else if (REDIS_VERSION.isGreaterThanOrEqualTo("6.2.0")) { result = - concatenateArrays( - result, - new Object[] { - "0-0", Map.of("0-3", new String[][] {{"field3", "value3"}, new String[] {}}) - , // xautoclaim(streamKey1, groupName1, consumer1, 0L, "0-0") - "0-1", "0-3", new String[] {} - } // xautoclaimJustId(streamKey1, groupName1, consumer1, 0L, "0-0"); - ); + concatenateArrays( + result, + new Object[] { + new Object[] { + "0-0", + Map.of("0-3", new String[][] {{"field3", "value3"}}) + },// xautoclaim(streamKey1, groupName1, consumer1, 0L, "0-0") + new Object[] {"0-0", new String[]{"0-3"}}// xautoclaimJustId(streamKey1, groupName1, consumer1, 0L, "0-0"); + } + ); } result = concatenateArrays( From 3d8e95fc7523b177c959def7f013c191560c173c Mon Sep 17 00:00:00 2001 From: jamesx-improving Date: Fri, 5 Jul 2024 12:23:53 -0700 Subject: [PATCH 11/17] add examples to comments/docs --- .../api/commands/StreamBaseCommands.java | 112 ++++++++++++++---- 1 file changed, 86 insertions(+), 26 deletions(-) diff --git a/java/client/src/main/java/glide/api/commands/StreamBaseCommands.java b/java/client/src/main/java/glide/api/commands/StreamBaseCommands.java index 3bb2639cff..922f595f23 100644 --- a/java/client/src/main/java/glide/api/commands/StreamBaseCommands.java +++ b/java/client/src/main/java/glide/api/commands/StreamBaseCommands.java @@ -1393,19 +1393,14 @@ CompletableFuture[]> xinfoConsumers( * longer exist in the stream. These IDs are deleted from the Pending Entries List. * @example *
-     *      // Redis version < 7.0.0:
-     *      Object[] results = client.xautoclaim("my_stream", "my_group", "my_consumer", 3_600_000L, "0-0").get();
-     * for (Object element: results) {
-     *     System.out.println(element);
-     *
-     *     for (String key: element.get(key)) {
-     *
-     *          for(String entry: ){
-     *             System.out.println(ke);
-     *          }
-     *     }
-     * }
-     *      // Redis version 7.0.0 and above
+     *      Object[] result = client.xautoclaim("my_stream", "my_group", "my_consumer", 3_600_000L, "0-0").get();
+     *      assertEquals(streamid_1, result[0]);
+     *      assertDeepEquals(Map.of(streamid_0, new String[][] {{"f1", "v1"}}),result[1]);
+     *          // if using Redis 7.0.0 or above, responses also include a list of entry IDs that were removed from the Pending
+     *          //     Entries List because they no longer exist in the stream
+     *      if(REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")){
+     *          assertDeepEquals(new Object[] {},result[2]);
+     *      }
      *  
*/ CompletableFuture xautoclaim( @@ -1431,19 +1426,14 @@ CompletableFuture xautoclaim( * longer exist in the stream. These IDs are deleted from the Pending Entries List. * @example *
-     *      // Redis version < 7.0.0:
-     *      Object[] results = client.xautoclaim("my_stream", "my_group", "my_consumer", 3_600_000L, "0-0").get();
-     * for (Object element: results) {
-     *     System.out.println(element);
-     *
-     *     for (String key: element.get(key)) {
-     *
-     *          for(String entry: ){
-     *             System.out.println(ke);
-     *          }
-     *     }
-     * }
-     *      // Redis version 7.0.0 and above
+     *      Object[] result = client.xautoclaim("my_stream", "my_group", "my_consumer", 3_600_000L, "0-0").get();
+     *      assertEquals(streamid_1, result[0]);
+     *      assertDeepEquals(Map.of(streamid_0, new String[][] {{"f1", "v1"}}),result[1]);
+     *          // if using Redis 7.0.0 or above, responses also include a list of entry IDs that were removed from the Pending
+     *          //     Entries List because they no longer exist in the stream
+     *      if(REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")){
+     *          assertDeepEquals(new Object[] {},result[2]);
+     *      }
      *  
*/ CompletableFuture xautoclaim( @@ -1468,6 +1458,17 @@ CompletableFuture xautoclaim( * [field2, value2], ...]`. - If you are using Redis 7.0.0 or above, the response list will * also include a list containing the message IDs that were in the Pending Entries List but no * longer exist in the stream. These IDs are deleted from the Pending Entries List. + * @example + *
+     *      Object[] result = client.xautoclaim("my_stream", "my_group", "my_consumer", 3_600_000L, "0-0", 1L).get();
+     *      assertEquals(streamid_1, result[0]);
+     *      assertDeepEquals(Map.of(streamid_0, new String[][] {{"f1", "v1"}}),result[1]);
+     *          // if using Redis 7.0.0 or above, responses also include a list of entry IDs that were removed from the Pending
+     *          //     Entries List because they no longer exist in the stream
+     *      if(REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")){
+     *          assertDeepEquals(new Object[] {},result[2]);
+     *      }
+     *  
*/ CompletableFuture xautoclaim( String key, String group, String consumer, long minIdleTime, String start, long count); @@ -1491,6 +1492,17 @@ CompletableFuture xautoclaim( * [field2, value2], ...]`. - If you are using Redis 7.0.0 or above, the response list will * also include a list containing the message IDs that were in the Pending Entries List but no * longer exist in the stream. These IDs are deleted from the Pending Entries List. + * @example + *
+     *      Object[] result = client.xautoclaim("my_stream", "my_group", "my_consumer", 3_600_000L, "0-0", 1L).get();
+     *      assertEquals(streamid_1, result[0]);
+     *      assertDeepEquals(Map.of(streamid_0, new String[][] {{"f1", "v1"}}),result[1]);
+     *          // if using Redis 7.0.0 or above, responses also include a list of entry IDs that were removed from the Pending
+     *          //     Entries List because they no longer exist in the stream
+     *      if(REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")){
+     *          assertDeepEquals(new Object[] {},result[2]);
+     *      }
+     *  
*/ CompletableFuture xautoclaim( GlideString key, GlideString group, GlideString consumer, long minIdleTime, GlideString start, long count); @@ -1514,6 +1526,18 @@ CompletableFuture xautoclaim( * above, the response list will also include a list containing the message IDs that were in * the Pending Entries List but no longer exist in the stream. These IDs are deleted from the * Pending Entries List. + * @example + *
+     *      Object[] result = client.xautoclaimJustId("my_stream", "my_group", "my_consumer", 3_600_000L, "0-0").get();
+     *      assertEquals(zeroStreamId, result[0]);
+     *         if (REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")) {
+     *             assertDeepEquals(new String[] {streamid_0, streamid_1, streamid_3}, result[1]);
+     *             assertDeepEquals(new Object[] {}, result[2]);
+     *         }
+     *         else {
+     *             assertDeepEquals(new String[] {streamid_0, streamid_1, streamid_2, streamid_3}, result[1]);
+     *         }
+     *  
*/ CompletableFuture xautoclaimJustId( String key, String group, String consumer, long minIdleTime, String start); @@ -1537,6 +1561,18 @@ CompletableFuture xautoclaimJustId( * above, the response list will also include a list containing the message IDs that were in * the Pending Entries List but no longer exist in the stream. These IDs are deleted from the * Pending Entries List. + * @example + *
+     *      Object[] result = client.xautoclaimJustId("my_stream", "my_group", "my_consumer", 3_600_000L, "0-0").get();
+     *      assertEquals(zeroStreamId, result[0]);
+     *         if (REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")) {
+     *             assertDeepEquals(new String[] {streamid_0, streamid_1, streamid_3}, result[1]);
+     *             assertDeepEquals(new Object[] {}, result[2]);
+     *         }
+     *         else {
+     *             assertDeepEquals(new String[] {streamid_0, streamid_1, streamid_2, streamid_3}, result[1]);
+     *         }
+     *  
*/ CompletableFuture xautoclaimJustId( GlideString key, GlideString group, GlideString consumer, long minIdleTime, GlideString start); @@ -1561,6 +1597,18 @@ CompletableFuture xautoclaimJustId( * above, the response list will also include a list containing the message IDs that were in * the Pending Entries List but no longer exist in the stream. These IDs are deleted from the * Pending Entries List. + * @example + *
+     *      Object[] result = client.xautoclaimJustId("my_stream", "my_group", "my_consumer", 3_600_000L, "0-0", 1L).get();
+     *      assertEquals(zeroStreamId, result[0]);
+     *         if (REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")) {
+     *             assertDeepEquals(new String[] {streamid_0, streamid_1, streamid_3}, result[1]);
+     *             assertDeepEquals(new Object[] {}, result[2]);
+     *         }
+     *         else {
+     *             assertDeepEquals(new String[] {streamid_0, streamid_1, streamid_2, streamid_3}, result[1]);
+     *         }
+     *  
*/ CompletableFuture xautoclaimJustId( String key, String group, String consumer, long minIdleTime, String start, long count); @@ -1585,6 +1633,18 @@ CompletableFuture xautoclaimJustId( * above, the response list will also include a list containing the message IDs that were in * the Pending Entries List but no longer exist in the stream. These IDs are deleted from the * Pending Entries List. + * @example + *
+     *      Object[] result = client.xautoclaimJustId("my_stream", "my_group", "my_consumer", 3_600_000L, "0-0", 1L).get();
+     *      assertEquals(zeroStreamId, result[0]);
+     *         if (REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")) {
+     *             assertDeepEquals(new String[] {streamid_0, streamid_1, streamid_3}, result[1]);
+     *             assertDeepEquals(new Object[] {}, result[2]);
+     *         }
+     *         else {
+     *             assertDeepEquals(new String[] {streamid_0, streamid_1, streamid_2, streamid_3}, result[1]);
+     *         }
+     *  
*/ CompletableFuture xautoclaimJustId( GlideString key, GlideString group, GlideString consumer, long minIdleTime, GlideString start, long count); From d0182755396930b7ea1775c8857bce103268d5d5 Mon Sep 17 00:00:00 2001 From: jamesx-improving Date: Fri, 5 Jul 2024 12:30:27 -0700 Subject: [PATCH 12/17] spotless --- .../src/main/java/glide/api/BaseClient.java | 141 +++++++++--------- .../api/commands/StreamBaseCommands.java | 26 +++- .../test/java/glide/api/RedisClientTest.java | 74 ++++++--- .../glide/api/models/TransactionTests.java | 7 +- .../test/java/glide/SharedCommandTests.java | 74 +++++---- .../java/glide/TransactionTestUtilities.java | 44 +++--- 6 files changed, 215 insertions(+), 151 deletions(-) diff --git a/java/client/src/main/java/glide/api/BaseClient.java b/java/client/src/main/java/glide/api/BaseClient.java index 5054396c71..95090df3ab 100644 --- a/java/client/src/main/java/glide/api/BaseClient.java +++ b/java/client/src/main/java/glide/api/BaseClient.java @@ -2803,20 +2803,19 @@ public CompletableFuture xautoclaim( long minIdleTime, @NonNull String start) { String[] args = new String[] {key, group, consumer, Long.toString(minIdleTime), start}; - return commandManager.submitNewCommand( - XAutoClaim, args, this::handleArrayResponse); + return commandManager.submitNewCommand(XAutoClaim, args, this::handleArrayResponse); } @Override public CompletableFuture xautoclaim( - @NonNull GlideString key, - @NonNull GlideString group, - @NonNull GlideString consumer, - long minIdleTime, - @NonNull GlideString start) { - GlideString[] args = new GlideString[] {key, group, consumer, gs(Long.toString(minIdleTime)), start}; - return commandManager.submitNewCommand( - XAutoClaim, args, this::handleArrayResponse); + @NonNull GlideString key, + @NonNull GlideString group, + @NonNull GlideString consumer, + long minIdleTime, + @NonNull GlideString start) { + GlideString[] args = + new GlideString[] {key, group, consumer, gs(Long.toString(minIdleTime)), start}; + return commandManager.submitNewCommand(XAutoClaim, args, this::handleArrayResponse); } @Override @@ -2827,26 +2826,32 @@ public CompletableFuture xautoclaim( long minIdleTime, @NonNull String start, long count) { - String[] args = new String[] { - key, group, consumer, Long.toString(minIdleTime), start, "COUNT", Long.toString(count) - }; - return commandManager.submitNewCommand( - XAutoClaim, args, this::handleArrayResponse); + String[] args = + new String[] { + key, group, consumer, Long.toString(minIdleTime), start, "COUNT", Long.toString(count) + }; + return commandManager.submitNewCommand(XAutoClaim, args, this::handleArrayResponse); } @Override public CompletableFuture xautoclaim( - @NonNull GlideString key, - @NonNull GlideString group, - @NonNull GlideString consumer, - long minIdleTime, - @NonNull GlideString start, - long count) { - GlideString[] args = new GlideString[] { - key, group, consumer, gs(Long.toString(minIdleTime)), start, gs("COUNT"), gs(Long.toString(count)) - }; - return commandManager.submitNewCommand( - XAutoClaim, args, this::handleArrayResponse); + @NonNull GlideString key, + @NonNull GlideString group, + @NonNull GlideString consumer, + long minIdleTime, + @NonNull GlideString start, + long count) { + GlideString[] args = + new GlideString[] { + key, + group, + consumer, + gs(Long.toString(minIdleTime)), + start, + gs("COUNT"), + gs(Long.toString(count)) + }; + return commandManager.submitNewCommand(XAutoClaim, args, this::handleArrayResponse); } @Override @@ -2856,21 +2861,23 @@ public CompletableFuture xautoclaimJustId( @NonNull String consumer, long minIdleTime, @NonNull String start) { - String[] args = new String[] {key, group, consumer, Long.toString(minIdleTime), start, "JUSTID"}; - return commandManager.submitNewCommand( - XAutoClaim, args, this::handleArrayResponse); + String[] args = + new String[] {key, group, consumer, Long.toString(minIdleTime), start, "JUSTID"}; + return commandManager.submitNewCommand(XAutoClaim, args, this::handleArrayResponse); } @Override public CompletableFuture xautoclaimJustId( - @NonNull GlideString key, - @NonNull GlideString group, - @NonNull GlideString consumer, - long minIdleTime, - @NonNull GlideString start) { - GlideString[] args = new GlideString[] {key, group, consumer, gs(Long.toString(minIdleTime)), start, gs("JUSTID")}; - return commandManager.submitNewCommand( - XAutoClaim, args, this::handleArrayResponse); + @NonNull GlideString key, + @NonNull GlideString group, + @NonNull GlideString consumer, + long minIdleTime, + @NonNull GlideString start) { + GlideString[] args = + new GlideString[] { + key, group, consumer, gs(Long.toString(minIdleTime)), start, gs("JUSTID") + }; + return commandManager.submitNewCommand(XAutoClaim, args, this::handleArrayResponse); } @Override @@ -2881,40 +2888,40 @@ public CompletableFuture xautoclaimJustId( long minIdleTime, @NonNull String start, long count) { - String[] args = new String[] { - key, - group, - consumer, - Long.toString(minIdleTime), - start, - "COUNT", - Long.toString(count), - "JUSTID" - }; - return commandManager.submitNewCommand( - XAutoClaim, args, this::handleArrayResponse); + String[] args = + new String[] { + key, + group, + consumer, + Long.toString(minIdleTime), + start, + "COUNT", + Long.toString(count), + "JUSTID" + }; + return commandManager.submitNewCommand(XAutoClaim, args, this::handleArrayResponse); } @Override public CompletableFuture xautoclaimJustId( - @NonNull GlideString key, - @NonNull GlideString group, - @NonNull GlideString consumer, - long minIdleTime, - @NonNull GlideString start, - long count) { - GlideString[] args = new GlideString[] { - key, - group, - consumer, - gs(Long.toString(minIdleTime)), - start, - gs("COUNT"), - gs(Long.toString(count)), - gs("JUSTID") - }; - return commandManager.submitNewCommand( - XAutoClaim, args, this::handleArrayResponse); + @NonNull GlideString key, + @NonNull GlideString group, + @NonNull GlideString consumer, + long minIdleTime, + @NonNull GlideString start, + long count) { + GlideString[] args = + new GlideString[] { + key, + group, + consumer, + gs(Long.toString(minIdleTime)), + start, + gs("COUNT"), + gs(Long.toString(count)), + gs("JUSTID") + }; + return commandManager.submitNewCommand(XAutoClaim, args, this::handleArrayResponse); } @Override diff --git a/java/client/src/main/java/glide/api/commands/StreamBaseCommands.java b/java/client/src/main/java/glide/api/commands/StreamBaseCommands.java index 922f595f23..253a4627c9 100644 --- a/java/client/src/main/java/glide/api/commands/StreamBaseCommands.java +++ b/java/client/src/main/java/glide/api/commands/StreamBaseCommands.java @@ -1437,7 +1437,11 @@ CompletableFuture xautoclaim( * */ CompletableFuture xautoclaim( - GlideString key, GlideString group, GlideString consumer, long minIdleTime, GlideString start); + GlideString key, + GlideString group, + GlideString consumer, + long minIdleTime, + GlideString start); /** * Transfers ownership of pending stream entries that match the specified criteria. @@ -1505,7 +1509,12 @@ CompletableFuture xautoclaim( * */ CompletableFuture xautoclaim( - GlideString key, GlideString group, GlideString consumer, long minIdleTime, GlideString start, long count); + GlideString key, + GlideString group, + GlideString consumer, + long minIdleTime, + GlideString start, + long count); /** * Transfers ownership of pending stream entries that match the specified criteria. This command @@ -1575,7 +1584,11 @@ CompletableFuture xautoclaimJustId( * */ CompletableFuture xautoclaimJustId( - GlideString key, GlideString group, GlideString consumer, long minIdleTime, GlideString start); + GlideString key, + GlideString group, + GlideString consumer, + long minIdleTime, + GlideString start); /** * Transfers ownership of pending stream entries that match the specified criteria. This command @@ -1647,5 +1660,10 @@ CompletableFuture xautoclaimJustId( * */ CompletableFuture xautoclaimJustId( - GlideString key, GlideString group, GlideString consumer, long minIdleTime, GlideString start, long count); + GlideString key, + GlideString group, + GlideString consumer, + long minIdleTime, + GlideString start, + long count); } diff --git a/java/client/src/test/java/glide/api/RedisClientTest.java b/java/client/src/test/java/glide/api/RedisClientTest.java index 34653ff81e..7f84cdbb05 100644 --- a/java/client/src/test/java/glide/api/RedisClientTest.java +++ b/java/client/src/test/java/glide/api/RedisClientTest.java @@ -7759,12 +7759,15 @@ public void xautoclaim_binary_return_success() { Long minIdleTime = 18L; GlideString start = gs("0-0"); - GlideString[][] fieldValuesResult = {{gs("duration"), gs("12345")}, {gs("event-id"), gs("2")}, {gs("user-id"), gs("42")}}; + GlideString[][] fieldValuesResult = { + {gs("duration"), gs("12345")}, {gs("event-id"), gs("2")}, {gs("user-id"), gs("42")} + }; Map completedResult = Map.of(key, fieldValuesResult); GlideString[] deletedMessageIds = new GlideString[] {gs("13-1"), gs("46-2"), gs("89-3")}; - GlideString[] arguments = concatenateArrays(new GlideString[] {key, groupName, consumer, gs("18"), start}); + GlideString[] arguments = + concatenateArrays(new GlideString[] {key, groupName, consumer, gs("18"), start}); Object[] mockResult = new Object[] {start, completedResult, deletedMessageIds}; CompletableFuture testResponse = new CompletableFuture<>(); @@ -7772,11 +7775,11 @@ public void xautoclaim_binary_return_success() { // match on protobuf request when(commandManager.submitNewCommand(eq(XAutoClaim), eq(arguments), any())) - .thenReturn(testResponse); + .thenReturn(testResponse); // exercise CompletableFuture response = - service.xautoclaim(key, groupName, consumer, minIdleTime, start); + service.xautoclaim(key, groupName, consumer, minIdleTime, start); Object[] payload = response.get(); // verify @@ -7833,14 +7836,18 @@ public void xautoclaim_binary_with_count_return_success() { GlideString start = gs("0-0"); long count = 1234; - GlideString[][] fieldValuesResult = {{gs("duration"), gs("12345")}, {gs("event-id"), gs("2")}, {gs("user-id"), gs("42")}}; + GlideString[][] fieldValuesResult = { + {gs("duration"), gs("12345")}, {gs("event-id"), gs("2")}, {gs("user-id"), gs("42")} + }; Map completedResult = Map.of(key, fieldValuesResult); GlideString[] deletedMessageIds = new GlideString[] {gs("13-1"), gs("46-2"), gs("89-3")}; GlideString[] arguments = - concatenateArrays( - new GlideString[] {key, groupName, consumer, gs("18"), start, gs("COUNT"), gs(Long.toString(count))}); + concatenateArrays( + new GlideString[] { + key, groupName, consumer, gs("18"), start, gs("COUNT"), gs(Long.toString(count)) + }); Object[] mockResult = new Object[] {start, completedResult, deletedMessageIds}; CompletableFuture testResponse = new CompletableFuture<>(); @@ -7848,11 +7855,11 @@ public void xautoclaim_binary_with_count_return_success() { // match on protobuf request when(commandManager.submitNewCommand(eq(XAutoClaim), eq(arguments), any())) - .thenReturn(testResponse); + .thenReturn(testResponse); // exercise CompletableFuture response = - service.xautoclaim(key, groupName, consumer, minIdleTime, start, count); + service.xautoclaim(key, groupName, consumer, minIdleTime, start, count); Object[] payload = response.get(); // verify @@ -7906,13 +7913,16 @@ public void xautoclaimJustId_binary_return_success() { Long minIdleTime = 18L; GlideString start = gs("0-0"); - GlideString[][] fieldValuesResult = {{gs("duration"), gs("12345")}, {gs("event-id"), gs("2")}, {gs("user-id"), gs("42")}}; + GlideString[][] fieldValuesResult = { + {gs("duration"), gs("12345")}, {gs("event-id"), gs("2")}, {gs("user-id"), gs("42")} + }; Map completedResult = Map.of(key, fieldValuesResult); GlideString[] deletedMessageIds = new GlideString[] {gs("13-1"), gs("46-2"), gs("89-3")}; GlideString[] arguments = - concatenateArrays(new GlideString[] {key, groupName, consumer, gs("18"), start, gs("JUSTID")}); + concatenateArrays( + new GlideString[] {key, groupName, consumer, gs("18"), start, gs("JUSTID")}); Object[] mockResult = new Object[] {start, completedResult, deletedMessageIds}; CompletableFuture testResponse = new CompletableFuture<>(); @@ -7920,11 +7930,11 @@ public void xautoclaimJustId_binary_return_success() { // match on protobuf request when(commandManager.submitNewCommand(eq(XAutoClaim), eq(arguments), any())) - .thenReturn(testResponse); + .thenReturn(testResponse); // exercise CompletableFuture response = - service.xautoclaimJustId(key, groupName, consumer, minIdleTime, start); + service.xautoclaimJustId(key, groupName, consumer, minIdleTime, start); Object[] payload = response.get(); // verify @@ -7949,8 +7959,17 @@ public void xautoclaimJustId_with_count_return_success() { String[] deletedMessageIds = new String[] {"13-1", "46-2", "89-3"}; String[] arguments = - concatenateArrays( - new String[] {key, groupName, consumer, Long.toString(minIdleTime), start, "COUNT", Long.toString(count), "JUSTID"}); + concatenateArrays( + new String[] { + key, + groupName, + consumer, + Long.toString(minIdleTime), + start, + "COUNT", + Long.toString(count), + "JUSTID" + }); Object[] mockResult = new Object[] {start, completedResult, deletedMessageIds}; CompletableFuture testResponse = new CompletableFuture<>(); @@ -7958,11 +7977,11 @@ public void xautoclaimJustId_with_count_return_success() { // match on protobuf request when(commandManager.submitNewCommand(eq(XAutoClaim), eq(arguments), any())) - .thenReturn(testResponse); + .thenReturn(testResponse); // exercise CompletableFuture response = - service.xautoclaimJustId(key, groupName, consumer, minIdleTime, start, count); + service.xautoclaimJustId(key, groupName, consumer, minIdleTime, start, count); Object[] payload = response.get(); // verify @@ -7981,14 +8000,25 @@ public void xautoclaimJustId_binary_with_count_return_success() { GlideString start = gs("0-0"); long count = 1234; - GlideString[][] fieldValuesResult = {{gs("duration"), gs("12345")}, {gs("event-id"), gs("2")}, {gs("user-id"), gs("42")}}; + GlideString[][] fieldValuesResult = { + {gs("duration"), gs("12345")}, {gs("event-id"), gs("2")}, {gs("user-id"), gs("42")} + }; Map completedResult = Map.of(key, fieldValuesResult); GlideString[] deletedMessageIds = new GlideString[] {gs("13-1"), gs("46-2"), gs("89-3")}; GlideString[] arguments = - concatenateArrays( - new GlideString[] {key, groupName, consumer, gs(Long.toString(minIdleTime)), start, gs("COUNT"), gs(Long.toString(count)), gs("JUSTID")}); + concatenateArrays( + new GlideString[] { + key, + groupName, + consumer, + gs(Long.toString(minIdleTime)), + start, + gs("COUNT"), + gs(Long.toString(count)), + gs("JUSTID") + }); Object[] mockResult = new Object[] {start, completedResult, deletedMessageIds}; CompletableFuture testResponse = new CompletableFuture<>(); @@ -7996,11 +8026,11 @@ public void xautoclaimJustId_binary_with_count_return_success() { // match on protobuf request when(commandManager.submitNewCommand(eq(XAutoClaim), eq(arguments), any())) - .thenReturn(testResponse); + .thenReturn(testResponse); // exercise CompletableFuture response = - service.xautoclaimJustId(key, groupName, consumer, minIdleTime, start, count); + service.xautoclaimJustId(key, groupName, consumer, minIdleTime, start, count); Object[] payload = response.get(); // verify 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 8a0dff6a4e..b0a14d9892 100644 --- a/java/client/src/test/java/glide/api/models/TransactionTests.java +++ b/java/client/src/test/java/glide/api/models/TransactionTests.java @@ -969,14 +969,17 @@ InfScoreBound.NEGATIVE_INFINITY, new ScoreBoundary(3, false), new Limit(1, 2)), results.add(Pair.of(XAutoClaim, buildArgs("key", "group", "consumer", "99", "0-0"))); transaction.xautoclaim("key", "group", "consumer", 99L, "0-0", 1234L); - results.add(Pair.of(XAutoClaim, buildArgs("key", "group", "consumer", "99", "0-0", "COUNT", "1234"))); + results.add( + Pair.of(XAutoClaim, buildArgs("key", "group", "consumer", "99", "0-0", "COUNT", "1234"))); transaction.xautoclaimJustId("key", "group", "consumer", 99L, "0-0"); results.add(Pair.of(XAutoClaim, buildArgs("key", "group", "consumer", "99", "0-0", "JUSTID"))); transaction.xautoclaimJustId("key", "group", "consumer", 99L, "0-0", 1234L); results.add( - Pair.of(XAutoClaim, buildArgs("key", "group", "consumer", "99", "0-0", "COUNT", "1234", "JUSTID"))); + Pair.of( + XAutoClaim, + buildArgs("key", "group", "consumer", "99", "0-0", "COUNT", "1234", "JUSTID"))); transaction.time(); results.add(Pair.of(Time, buildArgs())); diff --git a/java/integTest/src/test/java/glide/SharedCommandTests.java b/java/integTest/src/test/java/glide/SharedCommandTests.java index 0a830d16c3..62c85b4d5b 100644 --- a/java/integTest/src/test/java/glide/SharedCommandTests.java +++ b/java/integTest/src/test/java/glide/SharedCommandTests.java @@ -7121,7 +7121,9 @@ public void xclaim_return_failures(BaseClient client) { @MethodSource("getClients") public void xautoclaim(BaseClient client) { String minVersion = "6.2.0"; - assumeTrue(REDIS_VERSION.isGreaterThanOrEqualTo(minVersion), "This feature added in redis " + minVersion); + assumeTrue( + REDIS_VERSION.isGreaterThanOrEqualTo(minVersion), + "This feature added in redis " + minVersion); boolean isVersion7OrAbove = REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0"); String key = UUID.randomUUID().toString(); String groupName = UUID.randomUUID().toString(); @@ -7129,7 +7131,7 @@ public void xautoclaim(BaseClient client) { String consumer = UUID.randomUUID().toString(); // Add 4 stream entries for consumer - String streamid_0 = client.xadd(key, Map.of("f1", "v1"/*, "f2", "v2"*/)).get(); + String streamid_0 = client.xadd(key, Map.of("f1", "v1" /*, "f2", "v2"*/)).get(); assertNotNull(streamid_0); String streamid_1 = client.xadd(key, Map.of("field1", "value1")).get(); assertNotNull(streamid_1); @@ -7140,32 +7142,35 @@ public void xautoclaim(BaseClient client) { // create group and consumer for the group assertEquals( - OK, - client - .xgroupCreate( - key, groupName, zeroStreamId, StreamGroupOptions.builder().makeStream().build()) - .get()); + OK, + client + .xgroupCreate( + key, groupName, zeroStreamId, StreamGroupOptions.builder().makeStream().build()) + .get()); // read the entire stream for the consumer and mark messages as pending var xreadgroup_result = client.xreadgroup(Map.of(key, ">"), groupName, consumer).get(); assertDeepEquals( - Map.of( - key, Map.of( - streamid_0, new String[][] {{"f1", "v1"}/*, {"f2", "v2"}*/}, - streamid_1, new String[][] {{"field1", "value1"}}, - streamid_2, new String[][] {{"field2", "value2"}}, - streamid_3, new String[][] {{"field3", "value3"}})), - xreadgroup_result); + key, + Map.of( + streamid_0, new String[][] {{"f1", "v1"} /*, {"f2", "v2"}*/}, + streamid_1, new String[][] {{"field1", "value1"}}, + streamid_2, new String[][] {{"field2", "value2"}}, + streamid_3, new String[][] {{"field3", "value3"}})), + xreadgroup_result); - Object[] xautoclaimResult1 = client.xautoclaim(key, groupName, consumer, 0L, zeroStreamId, 1L).get(); + Object[] xautoclaimResult1 = + client.xautoclaim(key, groupName, consumer, 0L, zeroStreamId, 1L).get(); assertEquals(streamid_1, xautoclaimResult1[0]); - assertDeepEquals(Map.of(streamid_0, new String[][] {{"f1", "v1"}/*, {"f2", "v2"}*/}), xautoclaimResult1[1]); + assertDeepEquals( + Map.of(streamid_0, new String[][] {{"f1", "v1"} /*, {"f2", "v2"}*/}), xautoclaimResult1[1]); - // if using Redis 7.0.0 or above, responses also include a list of entry IDs that were removed from the Pending + // if using Redis 7.0.0 or above, responses also include a list of entry IDs that were removed + // from the Pending // Entries List because they no longer exist in the stream if (REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")) { - assertDeepEquals(new Object[]{}, xautoclaimResult1[2]); + assertDeepEquals(new Object[] {}, xautoclaimResult1[2]); } // delete entry 1-2 @@ -7173,30 +7178,33 @@ public void xautoclaim(BaseClient client) { // autoclaim the rest of the entries Object[] xautoclaimResult2 = client.xautoclaim(key, groupName, consumer, 0L, streamid_1).get(); - assertEquals(zeroStreamId, xautoclaimResult2[0]); // "0-0" is returned to indicate the entire stream was scanned. - assertDeepEquals(Map.of( - streamid_1, new String[][] {{"field1", "value1"}}, - streamid_3, new String[][] {{"field3", "value3"}} - ), - xautoclaimResult2[1] - ); + assertEquals( + zeroStreamId, + xautoclaimResult2[0]); // "0-0" is returned to indicate the entire stream was scanned. + assertDeepEquals( + Map.of( + streamid_1, new String[][] {{"field1", "value1"}}, + streamid_3, new String[][] {{"field3", "value3"}}), + xautoclaimResult2[1]); if (REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")) { - assertDeepEquals(new String[]{streamid_2}, xautoclaimResult2[2]); + assertDeepEquals(new String[] {streamid_2}, xautoclaimResult2[2]); } - // autoclaim with JUSTID: result at index 1 does not contain fields/values of the claimed entries, only IDs - Object[] justIdResult = client.xautoclaimJustId(key, groupName, consumer, 0L, zeroStreamId).get(); + // autoclaim with JUSTID: result at index 1 does not contain fields/values of the claimed + // entries, only IDs + Object[] justIdResult = + client.xautoclaimJustId(key, groupName, consumer, 0L, zeroStreamId).get(); assertEquals(zeroStreamId, justIdResult[0]); if (REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")) { assertDeepEquals(new String[] {streamid_0, streamid_1, streamid_3}, justIdResult[1]); assertDeepEquals(new Object[] {}, justIdResult[2]); - } - else { - // in Redis < 7.0.0, specifically for XAUTOCLAIM with JUSTID, entry IDs that were in the Pending Entries List + } else { + // in Redis < 7.0.0, specifically for XAUTOCLAIM with JUSTID, entry IDs that were in the + // Pending Entries List // but are no longer in the stream still show up in the response - assertDeepEquals(new String[] {streamid_0, streamid_1, streamid_2, streamid_3}, justIdResult[1]); + assertDeepEquals( + new String[] {streamid_0, streamid_1, streamid_2, streamid_3}, justIdResult[1]); } - } @SneakyThrows diff --git a/java/integTest/src/test/java/glide/TransactionTestUtilities.java b/java/integTest/src/test/java/glide/TransactionTestUtilities.java index ae2d88f5b1..573f4e49f1 100644 --- a/java/integTest/src/test/java/glide/TransactionTestUtilities.java +++ b/java/integTest/src/test/java/glide/TransactionTestUtilities.java @@ -942,30 +942,28 @@ private static Object[] streamCommands(BaseTransaction transaction) { }; if (REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")) { result = - concatenateArrays( - result, - new Object[] { - new Object[]{ - "0-0", - Map.of("0-3", new String[][]{{"field3", "value3"}}), - new Object[]{} - }, // xautoclaim(streamKey1, groupName1, consumer1, 0L, "0-0") - new Object[] {"0-0", new String[]{"0-3"}, new Object[] {} } // xautoclaimJustId(streamKey1, groupName1, consumer1, 0L, "0-0"); - } - ); - } - else if (REDIS_VERSION.isGreaterThanOrEqualTo("6.2.0")) { + concatenateArrays( + result, + new Object[] { + new Object[] { + "0-0", Map.of("0-3", new String[][] {{"field3", "value3"}}), new Object[] {} + }, // xautoclaim(streamKey1, groupName1, consumer1, 0L, "0-0") + new Object[] { + "0-0", new String[] {"0-3"}, new Object[] {} + } // xautoclaimJustId(streamKey1, groupName1, consumer1, 0L, "0-0"); + }); + } else if (REDIS_VERSION.isGreaterThanOrEqualTo("6.2.0")) { result = - concatenateArrays( - result, - new Object[] { - new Object[] { - "0-0", - Map.of("0-3", new String[][] {{"field3", "value3"}}) - },// xautoclaim(streamKey1, groupName1, consumer1, 0L, "0-0") - new Object[] {"0-0", new String[]{"0-3"}}// xautoclaimJustId(streamKey1, groupName1, consumer1, 0L, "0-0"); - } - ); + concatenateArrays( + result, + new Object[] { + new Object[] { + "0-0", Map.of("0-3", new String[][] {{"field3", "value3"}}) + }, // xautoclaim(streamKey1, groupName1, consumer1, 0L, "0-0") + new Object[] { + "0-0", new String[] {"0-3"} + } // xautoclaimJustId(streamKey1, groupName1, consumer1, 0L, "0-0"); + }); } result = concatenateArrays( From 2bda4dda5dd3b5031bf11085daf1bb9650427883 Mon Sep 17 00:00:00 2001 From: jamesx-improving Date: Fri, 5 Jul 2024 15:03:52 -0700 Subject: [PATCH 13/17] addressing comments part 1 --- .../src/main/java/glide/api/BaseClient.java | 31 +- .../api/commands/StreamBaseCommands.java | 356 ++++++++++-------- .../glide/api/models/BaseTransaction.java | 119 +++--- .../java/glide/TransactionTestUtilities.java | 8 +- 4 files changed, 292 insertions(+), 222 deletions(-) diff --git a/java/client/src/main/java/glide/api/BaseClient.java b/java/client/src/main/java/glide/api/BaseClient.java index 95090df3ab..08e51dbb83 100644 --- a/java/client/src/main/java/glide/api/BaseClient.java +++ b/java/client/src/main/java/glide/api/BaseClient.java @@ -6,6 +6,7 @@ import static glide.api.models.commands.bitmap.BitFieldOptions.createBitFieldArgs; import static glide.api.models.commands.bitmap.BitFieldOptions.createBitFieldGlideStringArgs; import static glide.api.models.commands.stream.StreamClaimOptions.JUST_ID_REDIS_API; +import static glide.api.models.commands.stream.StreamReadOptions.READ_COUNT_REDIS_API; import static glide.ffi.resolvers.SocketListenerResolver.getSocket; import static glide.utils.ArrayTransformUtils.cast3DArray; import static glide.utils.ArrayTransformUtils.castArray; @@ -2815,7 +2816,7 @@ public CompletableFuture xautoclaim( @NonNull GlideString start) { GlideString[] args = new GlideString[] {key, group, consumer, gs(Long.toString(minIdleTime)), start}; - return commandManager.submitNewCommand(XAutoClaim, args, this::handleArrayResponse); + return commandManager.submitNewCommand(XAutoClaim, args, this::handleArrayResponseBinary); } @Override @@ -2828,7 +2829,13 @@ public CompletableFuture xautoclaim( long count) { String[] args = new String[] { - key, group, consumer, Long.toString(minIdleTime), start, "COUNT", Long.toString(count) + key, + group, + consumer, + Long.toString(minIdleTime), + start, + READ_COUNT_REDIS_API, + Long.toString(count) }; return commandManager.submitNewCommand(XAutoClaim, args, this::handleArrayResponse); } @@ -2848,10 +2855,10 @@ public CompletableFuture xautoclaim( consumer, gs(Long.toString(minIdleTime)), start, - gs("COUNT"), + gs(READ_COUNT_REDIS_API), gs(Long.toString(count)) }; - return commandManager.submitNewCommand(XAutoClaim, args, this::handleArrayResponse); + return commandManager.submitNewCommand(XAutoClaim, args, this::handleArrayResponseBinary); } @Override @@ -2862,7 +2869,7 @@ public CompletableFuture xautoclaimJustId( long minIdleTime, @NonNull String start) { String[] args = - new String[] {key, group, consumer, Long.toString(minIdleTime), start, "JUSTID"}; + new String[] {key, group, consumer, Long.toString(minIdleTime), start, JUST_ID_REDIS_API}; return commandManager.submitNewCommand(XAutoClaim, args, this::handleArrayResponse); } @@ -2875,9 +2882,9 @@ public CompletableFuture xautoclaimJustId( @NonNull GlideString start) { GlideString[] args = new GlideString[] { - key, group, consumer, gs(Long.toString(minIdleTime)), start, gs("JUSTID") + key, group, consumer, gs(Long.toString(minIdleTime)), start, gs(JUST_ID_REDIS_API) }; - return commandManager.submitNewCommand(XAutoClaim, args, this::handleArrayResponse); + return commandManager.submitNewCommand(XAutoClaim, args, this::handleArrayResponseBinary); } @Override @@ -2895,9 +2902,9 @@ public CompletableFuture xautoclaimJustId( consumer, Long.toString(minIdleTime), start, - "COUNT", + READ_COUNT_REDIS_API, Long.toString(count), - "JUSTID" + JUST_ID_REDIS_API }; return commandManager.submitNewCommand(XAutoClaim, args, this::handleArrayResponse); } @@ -2917,11 +2924,11 @@ public CompletableFuture xautoclaimJustId( consumer, gs(Long.toString(minIdleTime)), start, - gs("COUNT"), + gs(READ_COUNT_REDIS_API), gs(Long.toString(count)), - gs("JUSTID") + gs(JUST_ID_REDIS_API) }; - return commandManager.submitNewCommand(XAutoClaim, args, this::handleArrayResponse); + return commandManager.submitNewCommand(XAutoClaim, args, this::handleArrayResponseBinary); } @Override diff --git a/java/client/src/main/java/glide/api/commands/StreamBaseCommands.java b/java/client/src/main/java/glide/api/commands/StreamBaseCommands.java index 253a4627c9..6c54b7e111 100644 --- a/java/client/src/main/java/glide/api/commands/StreamBaseCommands.java +++ b/java/client/src/main/java/glide/api/commands/StreamBaseCommands.java @@ -1376,32 +1376,36 @@ CompletableFuture[]> xinfoConsumers( /** * Transfers ownership of pending stream entries that match the specified criteria. * - * @see valkey.io for details. + * @see valkey.io for details. * @param key The key of the stream. - * @param group The consumer group name + * @param group The consumer group name. * @param consumer The group consumer. * @param minIdleTime The minimum idle time for the message to be claimed. * @param start Filters the claimed entries to those that have an ID equal or greater than the * specified value. - * @return An array containing the following elements: - A stream ID to be used as the start - * argument for the next call to XAUTOCLAIM. This ID is equivalent to the next ID - * in the stream after the entries that were scanned, or "0-0" if the entire stream was - * scanned. - A mapping of the claimed entries, with the keys being the claimed entry IDs and - * the values being a 2D list of the field-value pairs in the format `[[field1, value1], - * [field2, value2], ...]`. - If you are using Redis 7.0.0 or above, the response list will - * also include a list containing the message IDs that were in the Pending Entries List but no - * longer exist in the stream. These IDs are deleted from the Pending Entries List. + * @return An array containing the following elements: + *
    + *
  • A stream ID to be used as the start argument for the next call to XAUTOCLAIM + * . This ID is equivalent to the next ID in the stream after the entries that + * were scanned, or "0-0" if the entire stream was scanned. + *
  • A mapping of the claimed entries, with the keys being the claimed entry IDs and the + * values being a 2D list of the field-value pairs in the format + * [[field1, value1], [field2, value2], ...]. + *
  • If you are using Redis 7.0.0 or above, the response list will also include a list + * containing the message IDs that were in the Pending Entries List but no longer exist + * in the stream. These IDs are deleted from the Pending Entries List. + *
+ * * @example - *
-     *      Object[] result = client.xautoclaim("my_stream", "my_group", "my_consumer", 3_600_000L, "0-0").get();
-     *      assertEquals(streamid_1, result[0]);
-     *      assertDeepEquals(Map.of(streamid_0, new String[][] {{"f1", "v1"}}),result[1]);
-     *          // if using Redis 7.0.0 or above, responses also include a list of entry IDs that were removed from the Pending
-     *          //     Entries List because they no longer exist in the stream
-     *      if(REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")){
-     *          assertDeepEquals(new Object[] {},result[2]);
-     *      }
-     *  
+ *
{@code
+     * Object[] result = client.xautoclaim("my_stream", "my_group", "my_consumer", 3_600_000L, "0-0").get();
+     * assertEquals(streamid_1, result[0]);
+     * assertDeepEquals(Map.of(streamid_0, new String[][] {{"f1", "v1"}}),result[1]);
+     * if(REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")){
+     *     assertDeepEquals(new Object[] {},result[2]);
+     * }
+     *
+     * }
*/ CompletableFuture xautoclaim( String key, String group, String consumer, long minIdleTime, String start); @@ -1409,32 +1413,36 @@ CompletableFuture xautoclaim( /** * Transfers ownership of pending stream entries that match the specified criteria. * - * @see valkey.io for details. + * @see valkey.io for details. * @param key The key of the stream. - * @param group The consumer group name + * @param group The consumer group name. * @param consumer The group consumer. * @param minIdleTime The minimum idle time for the message to be claimed. * @param start Filters the claimed entries to those that have an ID equal or greater than the * specified value. - * @return An array containing the following elements: - A stream ID to be used as the start - * argument for the next call to XAUTOCLAIM. This ID is equivalent to the next ID - * in the stream after the entries that were scanned, or "0-0" if the entire stream was - * scanned. - A mapping of the claimed entries, with the keys being the claimed entry IDs and - * the values being a 2D list of the field-value pairs in the format `[[field1, value1], - * [field2, value2], ...]`. - If you are using Redis 7.0.0 or above, the response list will - * also include a list containing the message IDs that were in the Pending Entries List but no - * longer exist in the stream. These IDs are deleted from the Pending Entries List. + * @return An array containing the following elements: + *
    + *
  • A stream ID to be used as the start argument for the next call to XAUTOCLAIM + * . This ID is equivalent to the next ID in the stream after the entries that + * were scanned, or "0-0" if the entire stream was scanned. + *
  • A mapping of the claimed entries, with the keys being the claimed entry IDs and the + * values being a 2D list of the field-value pairs in the format + * [[field1, value1], [field2, value2], ...]. + *
  • If you are using Redis 7.0.0 or above, the response list will also include a list + * containing the message IDs that were in the Pending Entries List but no longer exist + * in the stream. These IDs are deleted from the Pending Entries List. + *
+ * * @example - *
-     *      Object[] result = client.xautoclaim("my_stream", "my_group", "my_consumer", 3_600_000L, "0-0").get();
-     *      assertEquals(streamid_1, result[0]);
-     *      assertDeepEquals(Map.of(streamid_0, new String[][] {{"f1", "v1"}}),result[1]);
-     *          // if using Redis 7.0.0 or above, responses also include a list of entry IDs that were removed from the Pending
-     *          //     Entries List because they no longer exist in the stream
-     *      if(REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")){
-     *          assertDeepEquals(new Object[] {},result[2]);
-     *      }
-     *  
+ *
{@code
+     * Object[] result = client.xautoclaim(gs("my_stream"), gs("my_group"), gs("my_consumer"), 3_600_000L, gs("0-0")).get();
+     * assertEquals(streamid_1, result[0]);
+     * assertDeepEquals(Map.of(streamid_0, new GlideString[][] {{gs("f1"), gs("v1")}}),result[1]);
+     * if(REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")){
+     *     assertDeepEquals(new Object[] {},result[2]);
+     * }
+     *
+     * }
*/ CompletableFuture xautoclaim( GlideString key, @@ -1446,33 +1454,37 @@ CompletableFuture xautoclaim( /** * Transfers ownership of pending stream entries that match the specified criteria. * - * @see valkey.io for details. + * @see valkey.io for details. * @param key The key of the stream. - * @param group The consumer group name + * @param group The consumer group name. * @param consumer The group consumer. * @param minIdleTime The minimum idle time for the message to be claimed. * @param start Filters the claimed entries to those that have an ID equal or greater than the * specified value. * @param count Limits the number of claimed entries to the specified value. - * @return An array containing the following elements: - A stream ID to be used as the start - * argument for the next call to XAUTOCLAIM. This ID is equivalent to the next ID - * in the stream after the entries that were scanned, or "0-0" if the entire stream was - * scanned. - A mapping of the claimed entries, with the keys being the claimed entry IDs and - * the values being a 2D list of the field-value pairs in the format `[[field1, value1], - * [field2, value2], ...]`. - If you are using Redis 7.0.0 or above, the response list will - * also include a list containing the message IDs that were in the Pending Entries List but no - * longer exist in the stream. These IDs are deleted from the Pending Entries List. + * @return An array containing the following elements: + *
    + *
  • A stream ID to be used as the start argument for the next call to XAUTOCLAIM + * . This ID is equivalent to the next ID in the stream after the entries that + * were scanned, or "0-0" if the entire stream was scanned. + *
  • A mapping of the claimed entries, with the keys being the claimed entry IDs and the + * values being a 2D list of the field-value pairs in the format + * [[field1, value1], [field2, value2], ...]. + *
  • If you are using Redis 7.0.0 or above, the response list will also include a list + * containing the message IDs that were in the Pending Entries List but no longer exist + * in the stream. These IDs are deleted from the Pending Entries List. + *
+ * * @example - *
-     *      Object[] result = client.xautoclaim("my_stream", "my_group", "my_consumer", 3_600_000L, "0-0", 1L).get();
-     *      assertEquals(streamid_1, result[0]);
-     *      assertDeepEquals(Map.of(streamid_0, new String[][] {{"f1", "v1"}}),result[1]);
-     *          // if using Redis 7.0.0 or above, responses also include a list of entry IDs that were removed from the Pending
-     *          //     Entries List because they no longer exist in the stream
-     *      if(REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")){
-     *          assertDeepEquals(new Object[] {},result[2]);
-     *      }
-     *  
+ *
{@code
+     * Object[] result = client.xautoclaim("my_stream", "my_group", "my_consumer", 3_600_000L, "0-0", 1L).get();
+     * assertEquals(streamid_1, result[0]);
+     * assertDeepEquals(Map.of(streamid_0, new String[][] {{"f1", "v1"}}),result[1]);
+     * if(REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")){
+     *     assertDeepEquals(new Object[] {},result[2]);
+     * }
+     *
+     * }
*/ CompletableFuture xautoclaim( String key, String group, String consumer, long minIdleTime, String start, long count); @@ -1480,33 +1492,37 @@ CompletableFuture xautoclaim( /** * Transfers ownership of pending stream entries that match the specified criteria. * - * @see valkey.io for details. + * @see valkey.io for details. * @param key The key of the stream. - * @param group The consumer group name + * @param group The consumer group name. * @param consumer The group consumer. * @param minIdleTime The minimum idle time for the message to be claimed. * @param start Filters the claimed entries to those that have an ID equal or greater than the * specified value. * @param count Limits the number of claimed entries to the specified value. - * @return An array containing the following elements: - A stream ID to be used as the start - * argument for the next call to XAUTOCLAIM. This ID is equivalent to the next ID - * in the stream after the entries that were scanned, or "0-0" if the entire stream was - * scanned. - A mapping of the claimed entries, with the keys being the claimed entry IDs and - * the values being a 2D list of the field-value pairs in the format `[[field1, value1], - * [field2, value2], ...]`. - If you are using Redis 7.0.0 or above, the response list will - * also include a list containing the message IDs that were in the Pending Entries List but no - * longer exist in the stream. These IDs are deleted from the Pending Entries List. + * @return An array containing the following elements: + *
    + *
  • A stream ID to be used as the start argument for the next call to XAUTOCLAIM + * . This ID is equivalent to the next ID in the stream after the entries that + * were scanned, or "0-0" if the entire stream was scanned. + *
  • A mapping of the claimed entries, with the keys being the claimed entry IDs and the + * values being a 2D list of the field-value pairs in the format + * [[field1, value1], [field2, value2], ...]. + *
  • If you are using Redis 7.0.0 or above, the response list will also include a list + * containing the message IDs that were in the Pending Entries List but no longer exist + * in the stream. These IDs are deleted from the Pending Entries List. + *
+ * * @example - *
-     *      Object[] result = client.xautoclaim("my_stream", "my_group", "my_consumer", 3_600_000L, "0-0", 1L).get();
-     *      assertEquals(streamid_1, result[0]);
-     *      assertDeepEquals(Map.of(streamid_0, new String[][] {{"f1", "v1"}}),result[1]);
-     *          // if using Redis 7.0.0 or above, responses also include a list of entry IDs that were removed from the Pending
-     *          //     Entries List because they no longer exist in the stream
-     *      if(REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")){
-     *          assertDeepEquals(new Object[] {},result[2]);
-     *      }
-     *  
+ *
{@code
+     * Object[] result = client.xautoclaim(gs("my_stream"), gs("my_group"), gs("my_consumer"), 3_600_000L, gs("0-0"), 1L).get();
+     * assertEquals(streamid_1, result[0]);
+     * assertDeepEquals(Map.of(streamid_0, new GlideString[][] {{gs("f1"), gs("v1")}}),result[1]);
+     * if(REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")){
+     *     assertDeepEquals(new Object[] {},result[2]);
+     * }
+     *
+     * }
*/ CompletableFuture xautoclaim( GlideString key, @@ -1521,32 +1537,37 @@ CompletableFuture xautoclaim( * uses the JUSTID argument to further specify that the return value should contain a * list of claimed IDs without their field-value info. * - * @see valkey.io for details. + * @see valkey.io for details. * @param key The key of the stream. - * @param group The consumer group name + * @param group The consumer group name. * @param consumer The group consumer. * @param minIdleTime The minimum idle time for the message to be claimed. * @param start Filters the claimed entries to those that have an ID equal or greater than the * specified value. - * @return An array containing the following elements: - A stream ID to be used as the start - * argument for the next call to XAUTOCLAIM. This ID is equivalent to the next ID - * in the stream after the entries that were scanned, or "0-0" if the entire stream was - * scanned. - A list of the IDs for the claimed entries. - If you are using Redis 7.0.0 or - * above, the response list will also include a list containing the message IDs that were in - * the Pending Entries List but no longer exist in the stream. These IDs are deleted from the - * Pending Entries List. + * @return An array containing the following elements: + *
    + *
  • A stream ID to be used as the start argument for the next call to XAUTOCLAIM + * . This ID is equivalent to the next ID in the stream after the entries that + * were scanned, or "0-0" if the entire stream was scanned. + *
  • A list of the IDs for the claimed entries. + *
  • If you are using Redis 7.0.0 or above, the response list will also include a list + * containing the message IDs that were in the Pending Entries List but no longer exist + * in the stream. These IDs are deleted from the Pending Entries List. + *
+ * * @example - *
-     *      Object[] result = client.xautoclaimJustId("my_stream", "my_group", "my_consumer", 3_600_000L, "0-0").get();
-     *      assertEquals(zeroStreamId, result[0]);
-     *         if (REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")) {
-     *             assertDeepEquals(new String[] {streamid_0, streamid_1, streamid_3}, result[1]);
-     *             assertDeepEquals(new Object[] {}, result[2]);
-     *         }
-     *         else {
-     *             assertDeepEquals(new String[] {streamid_0, streamid_1, streamid_2, streamid_3}, result[1]);
-     *         }
-     *  
+ *
{@code
+     * Object[] result = client.xautoclaimJustId("my_stream", "my_group", "my_consumer", 3_600_000L, "0-0").get();
+     * assertEquals(zeroStreamId, result[0]);
+     *    if (REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")) {
+     *        assertDeepEquals(new String[] {streamid_0, streamid_1, streamid_3}, result[1]);
+     *        assertDeepEquals(new Object[] {}, result[2]);
+     *    }
+     *    else {
+     *        assertDeepEquals(new String[] {streamid_0, streamid_1, streamid_2, streamid_3}, result[1]);
+     *    }
+     *
+     * }
*/ CompletableFuture xautoclaimJustId( String key, String group, String consumer, long minIdleTime, String start); @@ -1556,32 +1577,37 @@ CompletableFuture xautoclaimJustId( * uses the JUSTID argument to further specify that the return value should contain a * list of claimed IDs without their field-value info. * - * @see valkey.io for details. + * @see valkey.io for details. * @param key The key of the stream. - * @param group The consumer group name + * @param group The consumer group name. * @param consumer The group consumer. * @param minIdleTime The minimum idle time for the message to be claimed. * @param start Filters the claimed entries to those that have an ID equal or greater than the * specified value. - * @return An array containing the following elements: - A stream ID to be used as the start - * argument for the next call to XAUTOCLAIM. This ID is equivalent to the next ID - * in the stream after the entries that were scanned, or "0-0" if the entire stream was - * scanned. - A list of the IDs for the claimed entries. - If you are using Redis 7.0.0 or - * above, the response list will also include a list containing the message IDs that were in - * the Pending Entries List but no longer exist in the stream. These IDs are deleted from the - * Pending Entries List. + * @return An array containing the following elements: + *
    + *
  • A stream ID to be used as the start argument for the next call to XAUTOCLAIM + * . This ID is equivalent to the next ID in the stream after the entries that + * were scanned, or "0-0" if the entire stream was scanned. + *
  • A list of the IDs for the claimed entries. + *
  • If you are using Redis 7.0.0 or above, the response list will also include a list + * containing the message IDs that were in the Pending Entries List but no longer exist + * in the stream. These IDs are deleted from the Pending Entries List. + *
+ * * @example - *
-     *      Object[] result = client.xautoclaimJustId("my_stream", "my_group", "my_consumer", 3_600_000L, "0-0").get();
-     *      assertEquals(zeroStreamId, result[0]);
-     *         if (REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")) {
-     *             assertDeepEquals(new String[] {streamid_0, streamid_1, streamid_3}, result[1]);
-     *             assertDeepEquals(new Object[] {}, result[2]);
-     *         }
-     *         else {
-     *             assertDeepEquals(new String[] {streamid_0, streamid_1, streamid_2, streamid_3}, result[1]);
-     *         }
-     *  
+ *
{@code
+     * Object[] result = client.xautoclaimJustId(gs("my_stream"), gs("my_group"), gs("my_consumer"), 3_600_000L, gs("0-0")).get();
+     * assertEquals(zeroStreamId, result[0]);
+     *    if (REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")) {
+     *        assertDeepEquals(new GlideString[] {streamid_0, streamid_1, streamid_3}, result[1]);
+     *        assertDeepEquals(new Object[] {}, result[2]);
+     *    }
+     *    else {
+     *        assertDeepEquals(new GlideString[] {streamid_0, streamid_1, streamid_2, streamid_3}, result[1]);
+     *    }
+     *
+     * }
*/ CompletableFuture xautoclaimJustId( GlideString key, @@ -1595,33 +1621,38 @@ CompletableFuture xautoclaimJustId( * uses the JUSTID argument to further specify that the return value should contain a * list of claimed IDs without their field-value info. * - * @see valkey.io for details. + * @see valkey.io for details. * @param key The key of the stream. - * @param group The consumer group name + * @param group The consumer group name. * @param consumer The group consumer. * @param minIdleTime The minimum idle time for the message to be claimed. * @param start Filters the claimed entries to those that have an ID equal or greater than the * specified value. * @param count Limits the number of claimed entries to the specified value. - * @return An array containing the following elements: - A stream ID to be used as the start - * argument for the next call to XAUTOCLAIM. This ID is equivalent to the next ID - * in the stream after the entries that were scanned, or "0-0" if the entire stream was - * scanned. - A list of the IDs for the claimed entries. - If you are using Redis 7.0.0 or - * above, the response list will also include a list containing the message IDs that were in - * the Pending Entries List but no longer exist in the stream. These IDs are deleted from the - * Pending Entries List. + * @return An array containing the following elements: + *
    + *
  • A stream ID to be used as the start argument for the next call to XAUTOCLAIM + * . This ID is equivalent to the next ID in the stream after the entries that + * were scanned, or "0-0" if the entire stream was scanned. + *
  • A list of the IDs for the claimed entries. + *
  • If you are using Redis 7.0.0 or above, the response list will also include a list + * containing the message IDs that were in the Pending Entries List but no longer exist + * in the stream. These IDs are deleted from the Pending Entries List. + *
+ * * @example - *
-     *      Object[] result = client.xautoclaimJustId("my_stream", "my_group", "my_consumer", 3_600_000L, "0-0", 1L).get();
-     *      assertEquals(zeroStreamId, result[0]);
-     *         if (REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")) {
-     *             assertDeepEquals(new String[] {streamid_0, streamid_1, streamid_3}, result[1]);
-     *             assertDeepEquals(new Object[] {}, result[2]);
-     *         }
-     *         else {
-     *             assertDeepEquals(new String[] {streamid_0, streamid_1, streamid_2, streamid_3}, result[1]);
-     *         }
-     *  
+ *
{@code
+     * Object[] result = client.xautoclaimJustId("my_stream", "my_group", "my_consumer", 3_600_000L, "0-0", 1L).get();
+     * assertEquals(zeroStreamId, result[0]);
+     *    if (REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")) {
+     *        assertDeepEquals(new String[] {streamid_0, streamid_1, streamid_3}, result[1]);
+     *        assertDeepEquals(new Object[] {}, result[2]);
+     *    }
+     *    else {
+     *        assertDeepEquals(new String[] {streamid_0, streamid_1, streamid_2, streamid_3}, result[1]);
+     *    }
+     *
+     * }
*/ CompletableFuture xautoclaimJustId( String key, String group, String consumer, long minIdleTime, String start, long count); @@ -1631,33 +1662,38 @@ CompletableFuture xautoclaimJustId( * uses the JUSTID argument to further specify that the return value should contain a * list of claimed IDs without their field-value info. * - * @see valkey.io for details. + * @see valkey.io for details. * @param key The key of the stream. - * @param group The consumer group name + * @param group The consumer group name. * @param consumer The group consumer. * @param minIdleTime The minimum idle time for the message to be claimed. * @param start Filters the claimed entries to those that have an ID equal or greater than the * specified value. * @param count Limits the number of claimed entries to the specified value. - * @return An array containing the following elements: - A stream ID to be used as the start - * argument for the next call to XAUTOCLAIM. This ID is equivalent to the next ID - * in the stream after the entries that were scanned, or "0-0" if the entire stream was - * scanned. - A list of the IDs for the claimed entries. - If you are using Redis 7.0.0 or - * above, the response list will also include a list containing the message IDs that were in - * the Pending Entries List but no longer exist in the stream. These IDs are deleted from the - * Pending Entries List. + * @return An array containing the following elements: + *
    + *
  • A stream ID to be used as the start argument for the next call to XAUTOCLAIM + * . This ID is equivalent to the next ID in the stream after the entries that + * were scanned, or "0-0" if the entire stream was scanned. + *
  • A list of the IDs for the claimed entries. + *
  • If you are using Redis 7.0.0 or above, the response list will also include a list + * containing the message IDs that were in the Pending Entries List but no longer exist + * in the stream. These IDs are deleted from the Pending Entries List. + *
+ * * @example - *
-     *      Object[] result = client.xautoclaimJustId("my_stream", "my_group", "my_consumer", 3_600_000L, "0-0", 1L).get();
-     *      assertEquals(zeroStreamId, result[0]);
-     *         if (REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")) {
-     *             assertDeepEquals(new String[] {streamid_0, streamid_1, streamid_3}, result[1]);
-     *             assertDeepEquals(new Object[] {}, result[2]);
-     *         }
-     *         else {
-     *             assertDeepEquals(new String[] {streamid_0, streamid_1, streamid_2, streamid_3}, result[1]);
-     *         }
-     *  
+ *
{@code
+     * Object[] result = client.xautoclaimJustId(gs("my_stream"), gs("my_group"), gs("my_consumer"), 3_600_000L, gs("0-0"), 1L).get();
+     * assertEquals(zeroStreamId, result[0]);
+     *    if (REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")) {
+     *        assertDeepEquals(new GlideString[] {streamid_0, streamid_1, streamid_3}, result[1]);
+     *        assertDeepEquals(new Object[] {}, result[2]);
+     *    }
+     *    else {
+     *        assertDeepEquals(new GlideString[] {streamid_0, streamid_1, streamid_2, streamid_3}, result[1]);
+     *    }
+     *
+     * }
*/ CompletableFuture xautoclaimJustId( GlideString key, 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 21e7b33e3d..11ab5ab93b 100644 --- a/java/client/src/main/java/glide/api/models/BaseTransaction.java +++ b/java/client/src/main/java/glide/api/models/BaseTransaction.java @@ -20,6 +20,7 @@ import static glide.api.models.commands.function.FunctionListOptions.WITH_CODE_REDIS_API; import static glide.api.models.commands.function.FunctionLoadOptions.REPLACE; import static glide.api.models.commands.stream.StreamClaimOptions.JUST_ID_REDIS_API; +import static glide.api.models.commands.stream.StreamReadOptions.READ_COUNT_REDIS_API; import static glide.utils.ArrayTransformUtils.flattenAllKeysFollowedByAllValues; import static glide.utils.ArrayTransformUtils.flattenMapToGlideStringArray; import static glide.utils.ArrayTransformUtils.flattenMapToGlideStringArrayValueFirst; @@ -4087,6 +4088,8 @@ public T xinfoConsumers(@NonNull ArgType key, @NonNull ArgType groupNa /** * Transfers ownership of pending stream entries that match the specified criteria. * + * @implNote {@link ArgType} is limited to {@link String} or {@link GlideString}, any other type + * will throw {@link IllegalArgumentException}. * @see valkey.io for details. * @param key The key of the stream. * @param group The consumer group name @@ -4094,21 +4097,25 @@ public T xinfoConsumers(@NonNull ArgType key, @NonNull ArgType groupNa * @param minIdleTime The minimum idle time for the message to be claimed. * @param start Filters the claimed entries to those that have an ID equal or greater than the * specified value. - * @return An array containing the following elements: - A stream ID to be used as the start - * argument for the next call to XAUTOCLAIM. This ID is equivalent to the next ID - * in the stream after the entries that were scanned, or "0-0" if the entire stream was - * scanned. - A mapping of the claimed entries, with the keys being the claimed entry IDs and - * the values being a 2D list of the field-value pairs in the format `[[field1, value1], - * [field2, value2], ...]`. - If you are using Redis 7.0.0 or above, the response list will - * also include a list containing the message IDs that were in the Pending Entries List but no - * longer exist in the stream. These IDs are deleted from the Pending Entries List. + * @return Command Response - An array containing the following elements: + *
    + *
  • A stream ID to be used as the start argument for the next call to XAUTOCLAIM + * . This ID is equivalent to the next ID in the stream after the entries that + * were scanned, or "0-0" if the entire stream was scanned. + *
  • A mapping of the claimed entries, with the keys being the claimed entry IDs and the + * values being a 2D list of the field-value pairs in the format + * [[field1, value1], [field2, value2], ...]. + *
  • If you are using Redis 7.0.0 or above, the response list will also include a list + * containing the message IDs that were in the Pending Entries List but no longer exist + * in the stream. These IDs are deleted from the Pending Entries List. + *
*/ public T xautoclaim( - @NonNull String key, - @NonNull String group, - @NonNull String consumer, + @NonNull ArgType key, + @NonNull ArgType group, + @NonNull ArgType consumer, long minIdleTime, - @NonNull String start) { + @NonNull ArgType start) { protobufTransaction.addCommands( buildCommand( XAutoClaim, @@ -4119,6 +4126,8 @@ public T xautoclaim( /** * Transfers ownership of pending stream entries that match the specified criteria. * + * @implNote {@link ArgType} is limited to {@link String} or {@link GlideString}, any other type + * will throw {@link IllegalArgumentException}. * @see valkey.io for details. * @param key The key of the stream. * @param group The consumer group name @@ -4127,21 +4136,25 @@ public T xautoclaim( * @param start Filters the claimed entries to those that have an ID equal or greater than the * specified value. * @param count Limits the number of claimed entries to the specified value. - * @return An array containing the following elements: - A stream ID to be used as the start - * argument for the next call to XAUTOCLAIM. This ID is equivalent to the next ID - * in the stream after the entries that were scanned, or "0-0" if the entire stream was - * scanned. - A mapping of the claimed entries, with the keys being the claimed entry IDs and - * the values being a 2D list of the field-value pairs in the format `[[field1, value1], - * [field2, value2], ...]`. - If you are using Redis 7.0.0 or above, the response list will - * also include a list containing the message IDs that were in the Pending Entries List but no - * longer exist in the stream. These IDs are deleted from the Pending Entries List. + * @return Command Response - An array containing the following elements: + *
    + *
  • A stream ID to be used as the start argument for the next call to XAUTOCLAIM + * . This ID is equivalent to the next ID in the stream after the entries that + * were scanned, or "0-0" if the entire stream was scanned. + *
  • A mapping of the claimed entries, with the keys being the claimed entry IDs and the + * values being a 2D list of the field-value pairs in the format + * [[field1, value1], [field2, value2], ...]. + *
  • If you are using Redis 7.0.0 or above, the response list will also include a list + * containing the message IDs that were in the Pending Entries List but no longer exist + * in the stream. These IDs are deleted from the Pending Entries List. + *
*/ public T xautoclaim( - @NonNull String key, - @NonNull String group, - @NonNull String consumer, + @NonNull ArgType key, + @NonNull ArgType group, + @NonNull ArgType consumer, long minIdleTime, - @NonNull String start, + @NonNull ArgType start, long count) { protobufTransaction.addCommands( buildCommand( @@ -4152,7 +4165,7 @@ public T xautoclaim( .add(consumer) .add(minIdleTime) .add(start) - .add("COUNT") + .add(READ_COUNT_REDIS_API) .add(count))); return getThis(); } @@ -4162,6 +4175,8 @@ public T xautoclaim( * uses the JUSTID argument to further specify that the return value should contain a * list of claimed IDs without their field-value info. * + * @implNote {@link ArgType} is limited to {@link String} or {@link GlideString}, any other type + * will throw {@link IllegalArgumentException}. * @see valkey.io for details. * @param key The key of the stream. * @param group The consumer group name @@ -4169,20 +4184,23 @@ public T xautoclaim( * @param minIdleTime The minimum idle time for the message to be claimed. * @param start Filters the claimed entries to those that have an ID equal or greater than the * specified value. - * @return An array containing the following elements: - A stream ID to be used as the start - * argument for the next call to XAUTOCLAIM. This ID is equivalent to the next ID - * in the stream after the entries that were scanned, or "0-0" if the entire stream was - * scanned. - A list of the IDs for the claimed entries. - If you are using Redis 7.0.0 or - * above, the response list will also include a list containing the message IDs that were in - * the Pending Entries List but no longer exist in the stream. These IDs are deleted from the - * Pending Entries List. + * @return Command Response - An array containing the following elements: + *
    + *
  • A stream ID to be used as the start argument for the next call to XAUTOCLAIM + * . This ID is equivalent to the next ID in the stream after the entries that + * were scanned, or "0-0" if the entire stream was scanned. + *
  • A list of the IDs for the claimed entries. + *
  • If you are using Redis 7.0.0 or above, the response list will also include a list + * containing the message IDs that were in the Pending Entries List but no longer exist + * in the stream. These IDs are deleted from the Pending Entries List. + *
*/ public T xautoclaimJustId( - @NonNull String key, - @NonNull String group, - @NonNull String consumer, + @NonNull ArgType key, + @NonNull ArgType group, + @NonNull ArgType consumer, long minIdleTime, - @NonNull String start) { + @NonNull ArgType start) { protobufTransaction.addCommands( buildCommand( XAutoClaim, @@ -4201,6 +4219,8 @@ public T xautoclaimJustId( * uses the JUSTID argument to further specify that the return value should contain a * list of claimed IDs without their field-value info. * + * @implNote {@link ArgType} is limited to {@link String} or {@link GlideString}, any other type + * will throw {@link IllegalArgumentException}. * @see valkey.io for details. * @param key The key of the stream. * @param group The consumer group name @@ -4209,20 +4229,23 @@ public T xautoclaimJustId( * @param start Filters the claimed entries to those that have an ID equal or greater than the * specified value. * @param count Limits the number of claimed entries to the specified value. - * @return An array containing the following elements: - A stream ID to be used as the start - * argument for the next call to XAUTOCLAIM. This ID is equivalent to the next ID - * in the stream after the entries that were scanned, or "0-0" if the entire stream was - * scanned. - A list of the IDs for the claimed entries. - If you are using Redis 7.0.0 or - * above, the response list will also include a list containing the message IDs that were in - * the Pending Entries List but no longer exist in the stream. These IDs are deleted from the - * Pending Entries List. + * @return Command Response - An array containing the following elements: + *
    + *
  • A stream ID to be used as the start argument for the next call to XAUTOCLAIM + * . This ID is equivalent to the next ID in the stream after the entries that + * were scanned, or "0-0" if the entire stream was scanned. + *
  • A list of the IDs for the claimed entries. + *
  • If you are using Redis 7.0.0 or above, the response list will also include a list + * containing the message IDs that were in the Pending Entries List but no longer exist + * in the stream. These IDs are deleted from the Pending Entries List. + *
*/ public T xautoclaimJustId( - @NonNull String key, - @NonNull String group, - @NonNull String consumer, + @NonNull ArgType key, + @NonNull ArgType group, + @NonNull ArgType consumer, long minIdleTime, - @NonNull String start, + @NonNull ArgType start, long count) { protobufTransaction.addCommands( buildCommand( @@ -4233,7 +4256,7 @@ public T xautoclaimJustId( .add(consumer) .add(minIdleTime) .add(start) - .add("COUNT") + .add(READ_COUNT_REDIS_API) .add(count) .add(JUST_ID_REDIS_API))); return getThis(); diff --git a/java/integTest/src/test/java/glide/TransactionTestUtilities.java b/java/integTest/src/test/java/glide/TransactionTestUtilities.java index 573f4e49f1..df171931a8 100644 --- a/java/integTest/src/test/java/glide/TransactionTestUtilities.java +++ b/java/integTest/src/test/java/glide/TransactionTestUtilities.java @@ -946,10 +946,14 @@ private static Object[] streamCommands(BaseTransaction transaction) { result, new Object[] { new Object[] { - "0-0", Map.of("0-3", new String[][] {{"field3", "value3"}}), new Object[] {} + "0-0", + Map.of("0-3", new String[][] {{"field3", "value3"}}), + new Object[] {} // one more array is returned here for version >= 7.0.0 }, // xautoclaim(streamKey1, groupName1, consumer1, 0L, "0-0") new Object[] { - "0-0", new String[] {"0-3"}, new Object[] {} + "0-0", + new String[] {"0-3"}, + new Object[] {} // one more array is returned here for version >= 7.0.0 } // xautoclaimJustId(streamKey1, groupName1, consumer1, 0L, "0-0"); }); } else if (REDIS_VERSION.isGreaterThanOrEqualTo("6.2.0")) { From 74ac8894e891d6d10e0ffdc30a159e8fa593079e Mon Sep 17 00:00:00 2001 From: jamesx-improving Date: Fri, 5 Jul 2024 15:24:19 -0700 Subject: [PATCH 14/17] add integ test for GlideString --- .../test/java/glide/SharedCommandTests.java | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/java/integTest/src/test/java/glide/SharedCommandTests.java b/java/integTest/src/test/java/glide/SharedCommandTests.java index 62c85b4d5b..d6d1143a60 100644 --- a/java/integTest/src/test/java/glide/SharedCommandTests.java +++ b/java/integTest/src/test/java/glide/SharedCommandTests.java @@ -7129,6 +7129,7 @@ public void xautoclaim(BaseClient client) { String groupName = UUID.randomUUID().toString(); String zeroStreamId = "0-0"; String consumer = UUID.randomUUID().toString(); + String consumer2 = UUID.randomUUID().toString(); // Add 4 stream entries for consumer String streamid_0 = client.xadd(key, Map.of("f1", "v1" /*, "f2", "v2"*/)).get(); @@ -7177,17 +7178,17 @@ public void xautoclaim(BaseClient client) { assertEquals(1, client.xdel(key, new String[] {streamid_2}).get()); // autoclaim the rest of the entries - Object[] xautoclaimResult2 = client.xautoclaim(key, groupName, consumer, 0L, streamid_1).get(); + Object[] xautoclaimResult2 = client.xautoclaim(gs(key), gs(groupName), gs(consumer), 0L, gs(streamid_1)).get(); assertEquals( - zeroStreamId, + gs(zeroStreamId), xautoclaimResult2[0]); // "0-0" is returned to indicate the entire stream was scanned. assertDeepEquals( Map.of( - streamid_1, new String[][] {{"field1", "value1"}}, - streamid_3, new String[][] {{"field3", "value3"}}), + gs(streamid_1), new GlideString[][] {{gs("field1"), gs("value1")}}, + gs(streamid_3), new GlideString[][] {{gs("field3"), gs("value3")}}), xautoclaimResult2[1]); if (REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")) { - assertDeepEquals(new String[] {streamid_2}, xautoclaimResult2[2]); + assertDeepEquals(new GlideString[] {gs(streamid_2)}, xautoclaimResult2[2]); } // autoclaim with JUSTID: result at index 1 does not contain fields/values of the claimed @@ -7205,6 +7206,20 @@ public void xautoclaim(BaseClient client) { assertDeepEquals( new String[] {streamid_0, streamid_1, streamid_2, streamid_3}, justIdResult[1]); } + + Object[] justIdResultCount = + client.xautoclaimJustId(gs(key), gs(groupName), gs(consumer2), 0L, gs(zeroStreamId), 1L).get(); + assertEquals(gs(streamid_1), justIdResultCount[0]); + if (REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")) { + assertDeepEquals(new GlideString[] {gs(streamid_0)}, justIdResultCount[1]); + assertDeepEquals(new Object[] {}, justIdResultCount[2]); + } else { + // in Redis < 7.0.0, specifically for XAUTOCLAIM with JUSTID, entry IDs that were in the + // Pending Entries List + // but are no longer in the stream still show up in the response + assertDeepEquals( + new GlideString[] {gs(streamid_0), gs(streamid_2)}, justIdResultCount[1]); + } } @SneakyThrows From 3f89b6521ba444b5b91a29b6324da57d1b3d5957 Mon Sep 17 00:00:00 2001 From: jamesx-improving Date: Fri, 5 Jul 2024 16:05:12 -0700 Subject: [PATCH 15/17] addressing comments part 2 --- .../api/commands/StreamBaseCommands.java | 104 ++++++------------ .../glide/api/models/BaseTransaction.java | 26 ++--- .../test/java/glide/SharedCommandTests.java | 11 +- 3 files changed, 53 insertions(+), 88 deletions(-) diff --git a/java/client/src/main/java/glide/api/commands/StreamBaseCommands.java b/java/client/src/main/java/glide/api/commands/StreamBaseCommands.java index 6c54b7e111..8571498514 100644 --- a/java/client/src/main/java/glide/api/commands/StreamBaseCommands.java +++ b/java/client/src/main/java/glide/api/commands/StreamBaseCommands.java @@ -20,7 +20,7 @@ * Supports commands and transactions for the "Stream Commands" group for standalone and cluster * clients. * - * @see Stream Commands + * @see Stream Commands */ public interface StreamBaseCommands { @@ -676,7 +676,7 @@ CompletableFuture xgroupCreate( /** * Sets the last delivered ID for a consumer group. * - * @since Redis 7.0 and above + * @since Valkey 7.0 and above * @see valkey.io for details. * @param key The key of the stream. * @param groupName The consumer group name. @@ -1168,7 +1168,7 @@ CompletableFuture> xclaim( /** * Changes the ownership of a pending message. This function returns an array with - * only the message/entry IDs, and is equivalent to using JUSTID in the Redis API. + * only the message/entry IDs, and is equivalent to using JUSTID in the Valkey API. * * @see valkey.io for details. * @param key The key of the stream. @@ -1193,7 +1193,7 @@ CompletableFuture xclaimJustId( /** * Changes the ownership of a pending message. This function returns an array with - * only the message/entry IDs, and is equivalent to using JUSTID in the Redis API. + * only the message/entry IDs, and is equivalent to using JUSTID in the Valkey API. * * @see valkey.io for details. * @param key The key of the stream. @@ -1222,7 +1222,7 @@ CompletableFuture xclaimJustId( /** * Changes the ownership of a pending message. This function returns an array with - * only the message/entry IDs, and is equivalent to using JUSTID in the Redis API. + * only the message/entry IDs, and is equivalent to using JUSTID in the Valkey API. * * @see valkey.io for details. * @param key The key of the stream. @@ -1251,7 +1251,7 @@ CompletableFuture xclaimJustId( /** * Changes the ownership of a pending message. This function returns an array with - * only the message/entry IDs, and is equivalent to using JUSTID in the Redis API. + * only the message/entry IDs, and is equivalent to using JUSTID in the Valkey API. * * @see valkey.io for details. * @param key The key of the stream. @@ -1383,7 +1383,7 @@ CompletableFuture[]> xinfoConsumers( * @param minIdleTime The minimum idle time for the message to be claimed. * @param start Filters the claimed entries to those that have an ID equal or greater than the * specified value. - * @return An array containing the following elements: + * @return An array containing the following elements: *
    *
  • A stream ID to be used as the start argument for the next call to XAUTOCLAIM * . This ID is equivalent to the next ID in the stream after the entries that @@ -1391,7 +1391,7 @@ CompletableFuture[]> xinfoConsumers( *
  • A mapping of the claimed entries, with the keys being the claimed entry IDs and the * values being a 2D list of the field-value pairs in the format * [[field1, value1], [field2, value2], ...]. - *
  • If you are using Redis 7.0.0 or above, the response list will also include a list + *
  • If you are using Valkey 7.0.0 or above, the response list will also include a list * containing the message IDs that were in the Pending Entries List but no longer exist * in the stream. These IDs are deleted from the Pending Entries List. *
@@ -1401,10 +1401,7 @@ CompletableFuture[]> xinfoConsumers( * Object[] result = client.xautoclaim("my_stream", "my_group", "my_consumer", 3_600_000L, "0-0").get(); * assertEquals(streamid_1, result[0]); * assertDeepEquals(Map.of(streamid_0, new String[][] {{"f1", "v1"}}),result[1]); - * if(REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")){ - * assertDeepEquals(new Object[] {},result[2]); - * } - * + * assertDeepEquals(new Object[] {},result[2]); // version 7.0.0 or above * } */ CompletableFuture xautoclaim( @@ -1420,7 +1417,7 @@ CompletableFuture xautoclaim( * @param minIdleTime The minimum idle time for the message to be claimed. * @param start Filters the claimed entries to those that have an ID equal or greater than the * specified value. - * @return An array containing the following elements: + * @return An array containing the following elements: *
    *
  • A stream ID to be used as the start argument for the next call to XAUTOCLAIM * . This ID is equivalent to the next ID in the stream after the entries that @@ -1428,7 +1425,7 @@ CompletableFuture xautoclaim( *
  • A mapping of the claimed entries, with the keys being the claimed entry IDs and the * values being a 2D list of the field-value pairs in the format * [[field1, value1], [field2, value2], ...]. - *
  • If you are using Redis 7.0.0 or above, the response list will also include a list + *
  • If you are using Valkey 7.0.0 or above, the response list will also include a list * containing the message IDs that were in the Pending Entries List but no longer exist * in the stream. These IDs are deleted from the Pending Entries List. *
@@ -1438,10 +1435,7 @@ CompletableFuture xautoclaim( * Object[] result = client.xautoclaim(gs("my_stream"), gs("my_group"), gs("my_consumer"), 3_600_000L, gs("0-0")).get(); * assertEquals(streamid_1, result[0]); * assertDeepEquals(Map.of(streamid_0, new GlideString[][] {{gs("f1"), gs("v1")}}),result[1]); - * if(REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")){ - * assertDeepEquals(new Object[] {},result[2]); - * } - * + * assertDeepEquals(new Object[] {},result[2]); // version 7.0.0 or above * } */ CompletableFuture xautoclaim( @@ -1462,7 +1456,7 @@ CompletableFuture xautoclaim( * @param start Filters the claimed entries to those that have an ID equal or greater than the * specified value. * @param count Limits the number of claimed entries to the specified value. - * @return An array containing the following elements: + * @return An array containing the following elements: *
    *
  • A stream ID to be used as the start argument for the next call to XAUTOCLAIM * . This ID is equivalent to the next ID in the stream after the entries that @@ -1470,7 +1464,7 @@ CompletableFuture xautoclaim( *
  • A mapping of the claimed entries, with the keys being the claimed entry IDs and the * values being a 2D list of the field-value pairs in the format * [[field1, value1], [field2, value2], ...]. - *
  • If you are using Redis 7.0.0 or above, the response list will also include a list + *
  • If you are using Valkey 7.0.0 or above, the response list will also include a list * containing the message IDs that were in the Pending Entries List but no longer exist * in the stream. These IDs are deleted from the Pending Entries List. *
@@ -1480,10 +1474,7 @@ CompletableFuture xautoclaim( * Object[] result = client.xautoclaim("my_stream", "my_group", "my_consumer", 3_600_000L, "0-0", 1L).get(); * assertEquals(streamid_1, result[0]); * assertDeepEquals(Map.of(streamid_0, new String[][] {{"f1", "v1"}}),result[1]); - * if(REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")){ - * assertDeepEquals(new Object[] {},result[2]); - * } - * + * assertDeepEquals(new Object[] {},result[2]); // version 7.0.0 or above * } */ CompletableFuture xautoclaim( @@ -1500,7 +1491,7 @@ CompletableFuture xautoclaim( * @param start Filters the claimed entries to those that have an ID equal or greater than the * specified value. * @param count Limits the number of claimed entries to the specified value. - * @return An array containing the following elements: + * @return An array containing the following elements: *
    *
  • A stream ID to be used as the start argument for the next call to XAUTOCLAIM * . This ID is equivalent to the next ID in the stream after the entries that @@ -1508,7 +1499,7 @@ CompletableFuture xautoclaim( *
  • A mapping of the claimed entries, with the keys being the claimed entry IDs and the * values being a 2D list of the field-value pairs in the format * [[field1, value1], [field2, value2], ...]. - *
  • If you are using Redis 7.0.0 or above, the response list will also include a list + *
  • If you are using Valkey 7.0.0 or above, the response list will also include a list * containing the message IDs that were in the Pending Entries List but no longer exist * in the stream. These IDs are deleted from the Pending Entries List. *
@@ -1518,10 +1509,7 @@ CompletableFuture xautoclaim( * Object[] result = client.xautoclaim(gs("my_stream"), gs("my_group"), gs("my_consumer"), 3_600_000L, gs("0-0"), 1L).get(); * assertEquals(streamid_1, result[0]); * assertDeepEquals(Map.of(streamid_0, new GlideString[][] {{gs("f1"), gs("v1")}}),result[1]); - * if(REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")){ - * assertDeepEquals(new Object[] {},result[2]); - * } - * + * assertDeepEquals(new Object[] {},result[2]); // version 7.0.0 or above * } */ CompletableFuture xautoclaim( @@ -1544,13 +1532,13 @@ CompletableFuture xautoclaim( * @param minIdleTime The minimum idle time for the message to be claimed. * @param start Filters the claimed entries to those that have an ID equal or greater than the * specified value. - * @return An array containing the following elements: + * @return An array containing the following elements: *
    *
  • A stream ID to be used as the start argument for the next call to XAUTOCLAIM * . This ID is equivalent to the next ID in the stream after the entries that * were scanned, or "0-0" if the entire stream was scanned. *
  • A list of the IDs for the claimed entries. - *
  • If you are using Redis 7.0.0 or above, the response list will also include a list + *
  • If you are using Valkey 7.0.0 or above, the response list will also include a list * containing the message IDs that were in the Pending Entries List but no longer exist * in the stream. These IDs are deleted from the Pending Entries List. *
@@ -1559,14 +1547,8 @@ CompletableFuture xautoclaim( *
{@code
      * Object[] result = client.xautoclaimJustId("my_stream", "my_group", "my_consumer", 3_600_000L, "0-0").get();
      * assertEquals(zeroStreamId, result[0]);
-     *    if (REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")) {
-     *        assertDeepEquals(new String[] {streamid_0, streamid_1, streamid_3}, result[1]);
-     *        assertDeepEquals(new Object[] {}, result[2]);
-     *    }
-     *    else {
-     *        assertDeepEquals(new String[] {streamid_0, streamid_1, streamid_2, streamid_3}, result[1]);
-     *    }
-     *
+     * assertDeepEquals(new String[] {streamid_0, streamid_1, streamid_3}, result[1]);
+     * assertDeepEquals(new Object[] {}, result[2]); // version 7.0.0 or above
      * }
*/ CompletableFuture xautoclaimJustId( @@ -1584,13 +1566,13 @@ CompletableFuture xautoclaimJustId( * @param minIdleTime The minimum idle time for the message to be claimed. * @param start Filters the claimed entries to those that have an ID equal or greater than the * specified value. - * @return An array containing the following elements: + * @return An array containing the following elements: *
    *
  • A stream ID to be used as the start argument for the next call to XAUTOCLAIM * . This ID is equivalent to the next ID in the stream after the entries that * were scanned, or "0-0" if the entire stream was scanned. *
  • A list of the IDs for the claimed entries. - *
  • If you are using Redis 7.0.0 or above, the response list will also include a list + *
  • If you are using Valkey 7.0.0 or above, the response list will also include a list * containing the message IDs that were in the Pending Entries List but no longer exist * in the stream. These IDs are deleted from the Pending Entries List. *
@@ -1599,14 +1581,8 @@ CompletableFuture xautoclaimJustId( *
{@code
      * Object[] result = client.xautoclaimJustId(gs("my_stream"), gs("my_group"), gs("my_consumer"), 3_600_000L, gs("0-0")).get();
      * assertEquals(zeroStreamId, result[0]);
-     *    if (REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")) {
-     *        assertDeepEquals(new GlideString[] {streamid_0, streamid_1, streamid_3}, result[1]);
-     *        assertDeepEquals(new Object[] {}, result[2]);
-     *    }
-     *    else {
-     *        assertDeepEquals(new GlideString[] {streamid_0, streamid_1, streamid_2, streamid_3}, result[1]);
-     *    }
-     *
+     * assertDeepEquals(new GlideString[] {streamid_0, streamid_1, streamid_3}, result[1]);
+     * assertDeepEquals(new Object[] {}, result[2]); // version 7.0.0 or above
      * }
*/ CompletableFuture xautoclaimJustId( @@ -1629,13 +1605,13 @@ CompletableFuture xautoclaimJustId( * @param start Filters the claimed entries to those that have an ID equal or greater than the * specified value. * @param count Limits the number of claimed entries to the specified value. - * @return An array containing the following elements: + * @return An array containing the following elements: *
    *
  • A stream ID to be used as the start argument for the next call to XAUTOCLAIM * . This ID is equivalent to the next ID in the stream after the entries that * were scanned, or "0-0" if the entire stream was scanned. *
  • A list of the IDs for the claimed entries. - *
  • If you are using Redis 7.0.0 or above, the response list will also include a list + *
  • If you are using Valkey 7.0.0 or above, the response list will also include a list * containing the message IDs that were in the Pending Entries List but no longer exist * in the stream. These IDs are deleted from the Pending Entries List. *
@@ -1644,14 +1620,8 @@ CompletableFuture xautoclaimJustId( *
{@code
      * Object[] result = client.xautoclaimJustId("my_stream", "my_group", "my_consumer", 3_600_000L, "0-0", 1L).get();
      * assertEquals(zeroStreamId, result[0]);
-     *    if (REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")) {
-     *        assertDeepEquals(new String[] {streamid_0, streamid_1, streamid_3}, result[1]);
-     *        assertDeepEquals(new Object[] {}, result[2]);
-     *    }
-     *    else {
-     *        assertDeepEquals(new String[] {streamid_0, streamid_1, streamid_2, streamid_3}, result[1]);
-     *    }
-     *
+     * assertDeepEquals(new String[] {streamid_0, streamid_1, streamid_3}, result[1]);
+     * assertDeepEquals(new Object[] {}, result[2]); // version 7.0.0 or above
      * }
*/ CompletableFuture xautoclaimJustId( @@ -1670,13 +1640,13 @@ CompletableFuture xautoclaimJustId( * @param start Filters the claimed entries to those that have an ID equal or greater than the * specified value. * @param count Limits the number of claimed entries to the specified value. - * @return An array containing the following elements: + * @return An array containing the following elements: *
    *
  • A stream ID to be used as the start argument for the next call to XAUTOCLAIM * . This ID is equivalent to the next ID in the stream after the entries that * were scanned, or "0-0" if the entire stream was scanned. *
  • A list of the IDs for the claimed entries. - *
  • If you are using Redis 7.0.0 or above, the response list will also include a list + *
  • If you are using Valkey 7.0.0 or above, the response list will also include a list * containing the message IDs that were in the Pending Entries List but no longer exist * in the stream. These IDs are deleted from the Pending Entries List. *
@@ -1685,14 +1655,8 @@ CompletableFuture xautoclaimJustId( *
{@code
      * Object[] result = client.xautoclaimJustId(gs("my_stream"), gs("my_group"), gs("my_consumer"), 3_600_000L, gs("0-0"), 1L).get();
      * assertEquals(zeroStreamId, result[0]);
-     *    if (REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")) {
-     *        assertDeepEquals(new GlideString[] {streamid_0, streamid_1, streamid_3}, result[1]);
-     *        assertDeepEquals(new Object[] {}, result[2]);
-     *    }
-     *    else {
-     *        assertDeepEquals(new GlideString[] {streamid_0, streamid_1, streamid_2, streamid_3}, result[1]);
-     *    }
-     *
+     * assertDeepEquals(new GlideString[] {streamid_0, streamid_1, streamid_3}, result[1]);
+     * assertDeepEquals(new Object[] {}, result[2]); // version 7.0.0 or above
      * }
*/ CompletableFuture xautoclaimJustId( 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 11ab5ab93b..dd47a8c3ce 100644 --- a/java/client/src/main/java/glide/api/models/BaseTransaction.java +++ b/java/client/src/main/java/glide/api/models/BaseTransaction.java @@ -2470,8 +2470,8 @@ public T zrank(@NonNull ArgType key, @NonNull ArgType member) { * @see valkey.io for more details. * @param key The key of the sorted set. * @param member The member whose rank is to be retrieved. - * @return An array containing the rank (as Long) and score (as Double) - * of member in the sorted set.
+ * @return An array containing the rank (as Long) and score (as + * Double) of member in the sorted set.
* If key doesn't exist, or if member is not present in the set, * null will be returned. */ @@ -2512,9 +2512,9 @@ public T zrevrank(@NonNull ArgType key, @NonNull ArgType member) { * @see valkey.io for more details. * @param key The key of the sorted set. * @param member The member whose rank is to be retrieved. - * @return Command Response - An array containing the rank (as Long) and score (as - * Double) of member in the sorted set, where ranks are ordered from - * high to low based on scores.
+ * @return Command Response - An array containing the rank (as Long) and + * score (as Double) of member in the sorted set, where ranks are + * ordered from high to low based on scores.
* If key doesn't exist, or if member is not present in the set, * null will be returned. */ @@ -4090,14 +4090,14 @@ public T xinfoConsumers(@NonNull ArgType key, @NonNull ArgType groupNa * * @implNote {@link ArgType} is limited to {@link String} or {@link GlideString}, any other type * will throw {@link IllegalArgumentException}. - * @see valkey.io for details. + * @see valkey.io for details. * @param key The key of the stream. * @param group The consumer group name * @param consumer The group consumer. * @param minIdleTime The minimum idle time for the message to be claimed. * @param start Filters the claimed entries to those that have an ID equal or greater than the * specified value. - * @return Command Response - An array containing the following elements: + * @return Command Response - An array containing the following elements: *
    *
  • A stream ID to be used as the start argument for the next call to XAUTOCLAIM * . This ID is equivalent to the next ID in the stream after the entries that @@ -4128,7 +4128,7 @@ public T xautoclaim( * * @implNote {@link ArgType} is limited to {@link String} or {@link GlideString}, any other type * will throw {@link IllegalArgumentException}. - * @see valkey.io for details. + * @see valkey.io for details. * @param key The key of the stream. * @param group The consumer group name * @param consumer The group consumer. @@ -4136,7 +4136,7 @@ public T xautoclaim( * @param start Filters the claimed entries to those that have an ID equal or greater than the * specified value. * @param count Limits the number of claimed entries to the specified value. - * @return Command Response - An array containing the following elements: + * @return Command Response - An array containing the following elements: *
      *
    • A stream ID to be used as the start argument for the next call to XAUTOCLAIM * . This ID is equivalent to the next ID in the stream after the entries that @@ -4177,14 +4177,14 @@ public T xautoclaim( * * @implNote {@link ArgType} is limited to {@link String} or {@link GlideString}, any other type * will throw {@link IllegalArgumentException}. - * @see valkey.io for details. + * @see valkey.io for details. * @param key The key of the stream. * @param group The consumer group name * @param consumer The group consumer. * @param minIdleTime The minimum idle time for the message to be claimed. * @param start Filters the claimed entries to those that have an ID equal or greater than the * specified value. - * @return Command Response - An array containing the following elements: + * @return Command Response - An array containing the following elements: *
        *
      • A stream ID to be used as the start argument for the next call to XAUTOCLAIM * . This ID is equivalent to the next ID in the stream after the entries that @@ -4221,7 +4221,7 @@ public T xautoclaimJustId( * * @implNote {@link ArgType} is limited to {@link String} or {@link GlideString}, any other type * will throw {@link IllegalArgumentException}. - * @see valkey.io for details. + * @see valkey.io for details. * @param key The key of the stream. * @param group The consumer group name * @param consumer The group consumer. @@ -4229,7 +4229,7 @@ public T xautoclaimJustId( * @param start Filters the claimed entries to those that have an ID equal or greater than the * specified value. * @param count Limits the number of claimed entries to the specified value. - * @return Command Response - An array containing the following elements: + * @return Command Response - An array containing the following elements: *
          *
        • A stream ID to be used as the start argument for the next call to XAUTOCLAIM * . This ID is equivalent to the next ID in the stream after the entries that diff --git a/java/integTest/src/test/java/glide/SharedCommandTests.java b/java/integTest/src/test/java/glide/SharedCommandTests.java index d6d1143a60..927534865c 100644 --- a/java/integTest/src/test/java/glide/SharedCommandTests.java +++ b/java/integTest/src/test/java/glide/SharedCommandTests.java @@ -7124,7 +7124,6 @@ public void xautoclaim(BaseClient client) { assumeTrue( REDIS_VERSION.isGreaterThanOrEqualTo(minVersion), "This feature added in redis " + minVersion); - boolean isVersion7OrAbove = REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0"); String key = UUID.randomUUID().toString(); String groupName = UUID.randomUUID().toString(); String zeroStreamId = "0-0"; @@ -7178,7 +7177,8 @@ public void xautoclaim(BaseClient client) { assertEquals(1, client.xdel(key, new String[] {streamid_2}).get()); // autoclaim the rest of the entries - Object[] xautoclaimResult2 = client.xautoclaim(gs(key), gs(groupName), gs(consumer), 0L, gs(streamid_1)).get(); + Object[] xautoclaimResult2 = + client.xautoclaim(gs(key), gs(groupName), gs(consumer), 0L, gs(streamid_1)).get(); assertEquals( gs(zeroStreamId), xautoclaimResult2[0]); // "0-0" is returned to indicate the entire stream was scanned. @@ -7208,7 +7208,9 @@ public void xautoclaim(BaseClient client) { } Object[] justIdResultCount = - client.xautoclaimJustId(gs(key), gs(groupName), gs(consumer2), 0L, gs(zeroStreamId), 1L).get(); + client + .xautoclaimJustId(gs(key), gs(groupName), gs(consumer2), 0L, gs(zeroStreamId), 1L) + .get(); assertEquals(gs(streamid_1), justIdResultCount[0]); if (REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")) { assertDeepEquals(new GlideString[] {gs(streamid_0)}, justIdResultCount[1]); @@ -7217,8 +7219,7 @@ public void xautoclaim(BaseClient client) { // in Redis < 7.0.0, specifically for XAUTOCLAIM with JUSTID, entry IDs that were in the // Pending Entries List // but are no longer in the stream still show up in the response - assertDeepEquals( - new GlideString[] {gs(streamid_0), gs(streamid_2)}, justIdResultCount[1]); + assertDeepEquals(new GlideString[] {gs(streamid_0), gs(streamid_2)}, justIdResultCount[1]); } } From 436ab1a0ecaf45ba23d7f1fa1c22a3b38943d350 Mon Sep 17 00:00:00 2001 From: jamesx-improving Date: Fri, 5 Jul 2024 16:32:17 -0700 Subject: [PATCH 16/17] REDIS_VERSION -> SERVER_VERSION --- .../src/test/java/glide/SharedCommandTests.java | 14 +++++++------- .../test/java/glide/TransactionTestUtilities.java | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/java/integTest/src/test/java/glide/SharedCommandTests.java b/java/integTest/src/test/java/glide/SharedCommandTests.java index 927534865c..962185572d 100644 --- a/java/integTest/src/test/java/glide/SharedCommandTests.java +++ b/java/integTest/src/test/java/glide/SharedCommandTests.java @@ -3385,7 +3385,7 @@ public void bzpopmin(BaseClient client) { // // nothing popped out - key does not exist // assertNull( // client - // .bzpopmin(new GlideString[] {key3}, REDIS_VERSION.isLowerThan("7.0.0") + // .bzpopmin(new GlideString[] {key3}, SERVER_VERSION.isLowerThan("7.0.0") // ? 1. : 0.001) // .get()); @@ -3536,7 +3536,7 @@ public void bzpopmax(BaseClient client) { // // nothing popped out - key does not exist // assertNull( // client - // .bzpopmax(new GlideString[] {key3}, REDIS_VERSION.isLowerThan("7.0.0") + // .bzpopmax(new GlideString[] {key3}, SERVER_VERSION.isLowerThan("7.0.0") // ? 1. : 0.001) // .get()); @@ -7122,7 +7122,7 @@ public void xclaim_return_failures(BaseClient client) { public void xautoclaim(BaseClient client) { String minVersion = "6.2.0"; assumeTrue( - REDIS_VERSION.isGreaterThanOrEqualTo(minVersion), + SERVER_VERSION.isGreaterThanOrEqualTo(minVersion), "This feature added in redis " + minVersion); String key = UUID.randomUUID().toString(); String groupName = UUID.randomUUID().toString(); @@ -7169,7 +7169,7 @@ public void xautoclaim(BaseClient client) { // if using Redis 7.0.0 or above, responses also include a list of entry IDs that were removed // from the Pending // Entries List because they no longer exist in the stream - if (REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")) { + if (SERVER_VERSION.isGreaterThanOrEqualTo("7.0.0")) { assertDeepEquals(new Object[] {}, xautoclaimResult1[2]); } @@ -7187,7 +7187,7 @@ public void xautoclaim(BaseClient client) { gs(streamid_1), new GlideString[][] {{gs("field1"), gs("value1")}}, gs(streamid_3), new GlideString[][] {{gs("field3"), gs("value3")}}), xautoclaimResult2[1]); - if (REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")) { + if (SERVER_VERSION.isGreaterThanOrEqualTo("7.0.0")) { assertDeepEquals(new GlideString[] {gs(streamid_2)}, xautoclaimResult2[2]); } @@ -7196,7 +7196,7 @@ public void xautoclaim(BaseClient client) { Object[] justIdResult = client.xautoclaimJustId(key, groupName, consumer, 0L, zeroStreamId).get(); assertEquals(zeroStreamId, justIdResult[0]); - if (REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")) { + if (SERVER_VERSION.isGreaterThanOrEqualTo("7.0.0")) { assertDeepEquals(new String[] {streamid_0, streamid_1, streamid_3}, justIdResult[1]); assertDeepEquals(new Object[] {}, justIdResult[2]); } else { @@ -7212,7 +7212,7 @@ public void xautoclaim(BaseClient client) { .xautoclaimJustId(gs(key), gs(groupName), gs(consumer2), 0L, gs(zeroStreamId), 1L) .get(); assertEquals(gs(streamid_1), justIdResultCount[0]); - if (REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")) { + if (SERVER_VERSION.isGreaterThanOrEqualTo("7.0.0")) { assertDeepEquals(new GlideString[] {gs(streamid_0)}, justIdResultCount[1]); assertDeepEquals(new Object[] {}, justIdResultCount[2]); } else { diff --git a/java/integTest/src/test/java/glide/TransactionTestUtilities.java b/java/integTest/src/test/java/glide/TransactionTestUtilities.java index df171931a8..110e71e29b 100644 --- a/java/integTest/src/test/java/glide/TransactionTestUtilities.java +++ b/java/integTest/src/test/java/glide/TransactionTestUtilities.java @@ -862,7 +862,7 @@ private static Object[] streamCommands(BaseTransaction transaction) { StreamClaimOptions.builder().force().build()) .xpending(streamKey1, groupName1); - if (REDIS_VERSION.isGreaterThanOrEqualTo("6.2.0")) { + if (SERVER_VERSION.isGreaterThanOrEqualTo("6.2.0")) { transaction .xautoclaim(streamKey1, groupName1, consumer1, 0L, "0-0") .xautoclaimJustId(streamKey1, groupName1, consumer1, 0L, "0-0"); @@ -940,7 +940,7 @@ private static Object[] streamCommands(BaseTransaction transaction) { 1L, "0-3", "0-3", new Object[][] {{consumer1, "1"}} // xpending(streamKey1, groupName1) } }; - if (REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")) { + if (SERVER_VERSION.isGreaterThanOrEqualTo("7.0.0")) { result = concatenateArrays( result, @@ -956,7 +956,7 @@ private static Object[] streamCommands(BaseTransaction transaction) { new Object[] {} // one more array is returned here for version >= 7.0.0 } // xautoclaimJustId(streamKey1, groupName1, consumer1, 0L, "0-0"); }); - } else if (REDIS_VERSION.isGreaterThanOrEqualTo("6.2.0")) { + } else if (SERVER_VERSION.isGreaterThanOrEqualTo("6.2.0")) { result = concatenateArrays( result, From 3649c42e124e17e7f30c502cef0e9cc1a6551b09 Mon Sep 17 00:00:00 2001 From: jamesx-improving Date: Fri, 5 Jul 2024 16:47:05 -0700 Subject: [PATCH 17/17] fix integ test for 6.2 --- java/integTest/src/test/java/glide/SharedCommandTests.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/java/integTest/src/test/java/glide/SharedCommandTests.java b/java/integTest/src/test/java/glide/SharedCommandTests.java index 962185572d..7dc38a56d7 100644 --- a/java/integTest/src/test/java/glide/SharedCommandTests.java +++ b/java/integTest/src/test/java/glide/SharedCommandTests.java @@ -7216,10 +7216,7 @@ public void xautoclaim(BaseClient client) { assertDeepEquals(new GlideString[] {gs(streamid_0)}, justIdResultCount[1]); assertDeepEquals(new Object[] {}, justIdResultCount[2]); } else { - // in Redis < 7.0.0, specifically for XAUTOCLAIM with JUSTID, entry IDs that were in the - // Pending Entries List - // but are no longer in the stream still show up in the response - assertDeepEquals(new GlideString[] {gs(streamid_0), gs(streamid_2)}, justIdResultCount[1]); + assertDeepEquals(new GlideString[] {gs(streamid_0)}, justIdResultCount[1]); } }