Skip to content

Commit 4e5c041

Browse files
acarbonettoaaron-congotjzhang-BQyipin-chenshohamazon
committed
Java: Add XCLAIM command (valkey-io#1735)
* Java: Add XCLAIM command (#392) * Python: add XPENDING command (valkey-io#1704) * Python: add XPENDING command * PR suggestions * PR suggestions * Java: Add Command GeoSearch & GeoSearchStore * Java: Add Command GeoSearch & GeoSearchStore --------- * trigger build * Python: add RANDOMKEY command (valkey-io#1701) * Python: add RANDOMKEY command * Enable randomkey() test for that redis-rs is fixed Signed-off-by: Andrew Carbonetto <andrew.carbonetto@improving.com> * NOP push Signed-off-by: Andrew Carbonetto <andrew.carbonetto@improving.com> --------- Signed-off-by: Andrew Carbonetto <andrew.carbonetto@improving.com> Co-authored-by: Andrew Carbonetto <andrew.carbonetto@improving.com> * Python: add FUNCTION FLUSH command (valkey-io#1700) * Python: Added FUNCTION LOAD command * Python: adds FUNCTION FLUSH command * Updated CHANGELOG.md * Resolved merge issues related to FlushMode * Minor adjustments on command documentation * Revert one minor change in example. --------- Co-authored-by: Shoham Elias <shohame@amazon.com> Co-authored-by: Andrew Carbonetto <andrew.carbonetto@improving.com> * removing redis references * Java: Handle panics and errors in the Java FFI layer (valkey-io#1601) * Restructure Java FFI layer to handle errors properly * Fix failing tests * Address clippy lints * Add tests for error and panic handling * Add missing errors module * Fix clippy lint * Fix FFI tests * Apply Spotless * Fix some minor issue I forgot about * Add some comments * Apply Spotless * Make handle_panics return Option<T> instead * Java: Add SSCAN and ZSCAN commands (valkey-io#1705) * Java: Add `SSCAN` command (#394) * Add ScanOptions base class for scan-family options. * Expose the cursor as a String to support unsigned 64-bit cursor values. Co-authored-by: James Duong <james.duong@improving.com> * Java: Add `ZSCAN` command (#397) --------- Co-authored-by: James Duong <james.duong@improving.com> * WIP TODO: support transactions, docs, and more IT * Added more tests * Added tests and javadocs * Improved examples and tests * Correct use of SScanOptions instead of ScanOptions for SScan * Remove plumbing for SCAN command * Sleep after sadd() calls before sscan() calls Due to eventual consistency * Change sscan cursor to be a String Also fix bug in SharedCommandTests * WIP with todos * Add ZScan to TransactionTestUtilities * Spotless cleanup * Test fixes * Cleanup test code * Apply IntelliJ suggestions * Use String.valueOf() instead of concatenating empty string * Added better error info for set comparison failures * More logging for test failures * Add sleeps after zadd() calls To help make sure data is consistent without WAIT * Longer sleeps * Reduce wait time * Experiment with unsigned 64-bit cursors * Fix rebase error * WIP TODO: support transactions, docs, and more IT * Added more tests * Added tests and javadocs * Improved examples and tests * Apply PR comments * Fix method ordering in BaseTransaction * Fix broken line breaks within code tags in ScanOptions * More thoroughly test results in SharedCommandTests * Add better logging for set comparisons * Spotless * Sleep after sadd() calls before sscan() calls Due to eventual consistency * Change sscan cursor to be a String Also fix bug in SharedCommandTests * Update java/integTest/src/test/java/glide/SharedCommandTests.java Co-authored-by: Guian Gumpac <guian.gumpac@improving.com> * Update java/integTest/src/test/java/glide/SharedCommandTests.java Co-authored-by: Guian Gumpac <guian.gumpac@improving.com> * Fix rebase conflicts * Fix another rebase conflict * Spotless * Update java/client/src/main/java/glide/api/models/BaseTransaction.java Co-authored-by: Andrew Carbonetto <andrew.carbonetto@improving.com> * Update java/client/src/main/java/glide/api/models/BaseTransaction.java Co-authored-by: Andrew Carbonetto <andrew.carbonetto@improving.com> * Update java/client/src/main/java/glide/api/models/BaseTransaction.java Co-authored-by: Andrew Carbonetto <andrew.carbonetto@improving.com> * Update java/client/src/main/java/glide/api/models/BaseTransaction.java Co-authored-by: Andrew Carbonetto <andrew.carbonetto@improving.com> * Correctly use constants in TransactionTests * Rename ScanOptions to BaseScanOptions * Doc PR fixes * Treat end of cursor as failure * Spotless * Fixes * Update java/client/src/main/java/glide/api/commands/SortedSetBaseCommands.java Co-authored-by: Andrew Carbonetto <andrew.carbonetto@improving.com> * Update java/client/src/main/java/glide/api/commands/SortedSetBaseCommands.java Co-authored-by: Andrew Carbonetto <andrew.carbonetto@improving.com> * Update java/client/src/main/java/glide/api/commands/SortedSetBaseCommands.java Co-authored-by: Andrew Carbonetto <andrew.carbonetto@improving.com> * Update java/client/src/main/java/glide/api/commands/SortedSetBaseCommands.java Co-authored-by: Andrew Carbonetto <andrew.carbonetto@improving.com> * Minor doc changes --------- Co-authored-by: Guian Gumpac <guian.gumpac@improving.com> Co-authored-by: Andrew Carbonetto <andrew.carbonetto@improving.com> * CI: Add Support for Valkey 6.2, 7.0 and 7.2 (valkey-io#1711) - Transitioned the engine building process to be sourced from the Valkey repository. - Introduced compatibility with the following engine versions: Valkey and Redis 6.2 Valkey and Redis 7.0 Valkey and Redis 7.2 (first stable release of Valkey 7.2.5.) - Engine Installation Checks: Added check that the engine is installed with the requested version. - Moved the engine version matrix to a JSON file for better management and readability. - Fixed Object Encoding tests to expect quicklist on versions < 7.2 instead of 7.0 - Fixed C# and Java version parsing from redis-server -v output to support also Valkey's output - Updated the README file with the supported versions & engine typ * Python: add FUNCTION DELETE command (valkey-io#1714) * Python: adds FUNCTION DELETE command Co-authored-by: Shoham Elias <shohame@amazon.com> * Python: add `SSCAN` command (valkey-io#1709) * Added sscan command to python * Fixed formatting * Fixed CI failures * Lint * Improved example and test * Changes based on sscan java PR * Added to changelog * Addressed PR comments * Added string casting * Java: Add HSCAN command (valkey-io#1706) * Java: Add `SSCAN` command (#394) * Add ScanOptions base class for scan-family options. * Expose the cursor as a String to support unsigned 64-bit cursor values. Co-authored-by: James Duong <james.duong@improving.com> * Java: Add `ZSCAN` command (#397) --------- Co-authored-by: James Duong <james.duong@improving.com> * WIP TODO: support transactions, docs, and more IT * Added more tests * Added tests and javadocs * Improved examples and tests * Correct use of SScanOptions instead of ScanOptions for SScan * Remove plumbing for SCAN command * Sleep after sadd() calls before sscan() calls Due to eventual consistency * Change sscan cursor to be a String Also fix bug in SharedCommandTests * WIP with todos * Add ZScan to TransactionTestUtilities * Spotless cleanup * Test fixes * Cleanup test code * Apply IntelliJ suggestions * Use String.valueOf() instead of concatenating empty string * Added better error info for set comparison failures * More logging for test failures * Add sleeps after zadd() calls To help make sure data is consistent without WAIT * Longer sleeps * Reduce wait time * Experiment with unsigned 64-bit cursors * Fix rebase error * WIP TODO: support transactions, docs, and more IT * Added more tests * Added tests and javadocs * Improved examples and tests * Sleep after sadd() calls before sscan() calls Due to eventual consistency * Change sscan cursor to be a String Also fix bug in SharedCommandTests * Fix rebase conflicts * Fix another rebase conflict * Spotless * HScan * Flakey test * Add HScan transaction unit test * Rename ScanOptions to BaseScanOptions * Fix merge issues * Fix module-info ordering * Tidy up docs * PR comments Fix up merge duplication and use HScanOptions constants. --------- Co-authored-by: Guian Gumpac <guian.gumpac@improving.com> * Python: add LCS command (valkey-io#1716) * python: add LCS command (#406) * python: add LCS command * update CHANGELOG * add more comment explaning the functionality of the command * address comments on the docs * Java: Changed handling of large requests to transfer them as leaked pointers (valkey-io#1708) * Restructure Java FFI layer to handle errors properly * Address clippy lints * Add tests for error and panic handling * Fix FFI tests * Apply Spotless * Fix some minor issue I forgot about * Add API to create the leaked bytes vec * Bridge the MAX_REQUEST_ARGS_LENGTH constant from Rust to Java * Fix warnings in Rust * Update Java client to utilize the pointer with large argument sizes * Update createLeakedBytesVec to handle panics * spotless * Add docs and run Rust linters * Add large value tests * Fix transactions and add transaction tests * dummy commit for CI * Revert "dummy commit for CI" This reverts commit 3ed1937. * Fix JDK11 build issue Due to using a JDK17 function * Fix another JDK11 issue * Fix merge issues. * Remove unneccesary mut prefix * Clarify the MAX_REQUEST_ARGS_LENGTH_IN_BYTES constant * Fix merge issue --------- Co-authored-by: Jonathan Louie <jonathanl@bitquilltech.com> * Create initial workflow for publishing to Maven Central (valkey-io#1600) * WIP Create initial workflow for publishing to Maven Central (valkey-io#1594) * WIP Create initial workflow for publishing to Maven Central * Add classifier to workflow * Remove condition to allow all jobs to run * Try to fix Gradle workflow errors * Re-enable aws related options * Add missing property * Revert "Add missing property" This reverts commit efcedc5. * Add AWS_ACTIONS option * Sign JAR file * Fix signing issue * Try to fix issue with generating secring.gpg file * Fix path to secring.gpg * Try to fix secring.gpg retrieval issue * Remove base64 decode * Try to fix multi-line issue with GPG key secret * Go back to echo approach * Decode base64 properly this time * Use GPG_KEY_ID * Surround password in quotes * Publish JAR to local Maven and upload * Update examples build.gradle * Sign publishToMavenLocal build * Update version of Java JAR * Properly fetch src_folder variable contents * Reorganize JAR contents * Update path of uploaded JAR * Update artifact ID * Add missing comma * Replace placeholders in build.gradle * Update examples build.gradle * Remove test runs from java.yml workflow * Add debugging info to workflow * Adjust debug info * Readd placeholder text in build.gradle * Add more debug info * Change how the JAR is copied * Add configurations for ARM linux and x86 macos * Prevent output artifacts from being swallowed * Update build matrix to use proper RUNNERs * Try to use self-hosted runner for ARM Linux builds * Delete gradle-cd workflow * Add id-token permissions * Add step to setup self-hosted runner access * Add CONTAINER property to java.yml workflow * Remove install Redis step from java.yml workflow * Remove test-benchmark step from java.yml workflow * Fix issue with Java classifier * Update java.yml to use classifier * Bump version and add archiveClassifier * Change groupId to valkey-client * Update example and base archive name * Update workflow * Rename to glide-for-redis * Extracting Java Deployment to a different workflow Workflow will only trigger when a tag is pushed to the repo Version is extracted from the tag and replaced in the build.grade files reverted changes of java.yml file * trying to make the workflow to build * testing action to prepare build * forcing new action to trigger * Revert "forcing new action to trigger" This reverts commit d097a1f. * Revert "testing action to prepare build" This reverts commit 8864434. * Revert "trying to make the workflow to build" This reverts commit 143818a. * Revert "Extracting Java Deployment to a different workflow" This reverts commit faff846. * Revert "Revert "Extracting Java Deployment to a different workflow"" This reverts commit 11f8470. * fixing workflow * fixed path for the local maven * removing bundle from the tests fix to the JAVA CI not finding tests dependencies * fix java workflow * removing classifier from the pom * fixing concurrency * Remove publishToMavenLocal line in examples build.gradle * fix examples * cleaning up java.yml * testing removing test dependency * adding skip signing * Revert "adding skip signing" This reverts commit e448788. * Revert "testing removing test dependency" This reverts commit d0e06b7. * Revert "cleaning up java.yml" This reverts commit e7394d7. * removing dependency of singing in the local build * java.yml clean up * removing steps from java.yml * added comments * removed step on sed the examples and removed if always from the upload artifacts --------- Co-authored-by: affonsov <affonsov@bitquilltech.com> Co-authored-by: affonsov <affonso.vieira@improving.com> * valkey-io#1715: fix flakey test in xpending (valkey-io#1717) Signed-off-by: Andrew Carbonetto <andrew.carbonetto@improving.com> * Java: Adding command WAIT (valkey-io#1707) * Java: Adding command WAIT Java: Adding command WAIT * addressing comments * fixing timeout_idx in get_timeout_from_cmd_args call * update timeout check * fixing rust test * adding special case for WAIT * rust linter * remove special case in get_timeout_from_cmd_args * adding description for timeout 0 * rust linter * updating timeout test * changing transaction documentation --------- Co-authored-by: TJ Zhang <tj.zhang@improving.com> * support smismember with GlideString (valkey-io#1694) * Support GlideString for sdiff commands (valkey-io#1722) Co-authored-by: Yulazari <yulazari@b0de28c93acb.ant.amazon.com> * Updated attribution files * support hset, hget, lindex, linsert, blmove, incr, hlen and lmove wit… (valkey-io#1667) * Python: move the commands return value to bytes (valkey-io#1617) * In the case of Simple String, Bulk String, or Verbatim String commands, Bytes will be returned instead of strings. --------- Co-authored-by: GilboaAWS <gilboabg@amazon.com> Co-authored-by: Ubuntu <ubuntu@ip-172-31-41-43.eu-west-1.compute.internal> Co-authored-by: Adar Ovadia <adarov@amazon.com> Co-authored-by: Shoham Elias <shohame@amazon.com> Co-authored-by: Shoham Elias <116083498+shohamazon@users.noreply.github.com> * Java: Add XGROUP SETID command (valkey-io#1720) * Initial implementation of XGroupSetId * Unit tests * Add integration tests * PR feedback * Address PR comments doc updates * Add 7.0.0 transaction integration test * Java: update README directory to include Java's README.md (valkey-io#1734) add java part to readme directory * Java: Add XCLAIM command Signed-off-by: Andrew Carbonetto <andrew.carbonetto@improving.com> * Add unit tests Signed-off-by: Andrew Carbonetto <andrew.carbonetto@improving.com> * Add transaction tests Signed-off-by: Andrew Carbonetto <andrew.carbonetto@improving.com> * SPOTLESS Signed-off-by: Andrew Carbonetto <andrew.carbonetto@improving.com> * Update IT tests Signed-off-by: Andrew Carbonetto <andrew.carbonetto@improving.com> * Update IT tests Signed-off-by: Andrew Carbonetto <andrew.carbonetto@improving.com> * Add UT tests Signed-off-by: Andrew Carbonetto <andrew.carbonetto@improving.com> * Add transaction tests Signed-off-by: Andrew Carbonetto <andrew.carbonetto@improving.com> * Fix transaction tests Signed-off-by: Andrew Carbonetto <andrew.carbonetto@improving.com> * Update XCLAIM with options; remove LASTID Signed-off-by: Andrew Carbonetto <andrew.carbonetto@improving.com> * Add a couple more test cases Signed-off-by: Andrew Carbonetto <andrew.carbonetto@improving.com> * clean up Signed-off-by: Andrew Carbonetto <andrew.carbonetto@improving.com> * Clean rust Signed-off-by: Andrew Carbonetto <andrew.carbonetto@improving.com> * Add examples Signed-off-by: Andrew Carbonetto <andrew.carbonetto@improving.com> * Move to 2D string array in response Signed-off-by: Andrew Carbonetto <andrew.carbonetto@improving.com> * Fix Transaction tests; update examples Signed-off-by: Andrew Carbonetto <andrew.carbonetto@improving.com> * SPOTLESS Signed-off-by: Andrew Carbonetto <andrew.carbonetto@improving.com> --------- Signed-off-by: Andrew Carbonetto <andrew.carbonetto@improving.com> Co-authored-by: Aaron <69273634+aaron-congo@users.noreply.github.com> Co-authored-by: tjzhang-BQ <111323543+tjzhang-BQ@users.noreply.github.com> Co-authored-by: TJ Zhang <tj.zhang@improving.com> Co-authored-by: Yi-Pin Chen <yi-pin.chen@improving.com> Co-authored-by: Shoham Elias <shohame@amazon.com> Co-authored-by: jonathanl-bq <72158117+jonathanl-bq@users.noreply.github.com> Co-authored-by: James Duong <duong.james@gmail.com> Co-authored-by: Guian Gumpac <guian.gumpac@improving.com> Co-authored-by: Bar Shaul <88437685+barshaul@users.noreply.github.com> Co-authored-by: James Duong <james.duong@improving.com> Co-authored-by: James Xin <126831592+jamesx-improving@users.noreply.github.com> Co-authored-by: Jonathan Louie <jonathanl@bitquilltech.com> Co-authored-by: affonsov <affonsov@bitquilltech.com> Co-authored-by: affonsov <affonso.vieira@improving.com> Co-authored-by: Alon Arenberg <93711356+alon-arenberg@users.noreply.github.com> Co-authored-by: yulazariy <yulazari@amazon.com> Co-authored-by: Yulazari <yulazari@b0de28c93acb.ant.amazon.com> Co-authored-by: ort-bot <glide-for-redis@amazon.com> Co-authored-by: adarovadya <adarovadya@gmail.com> Co-authored-by: GilboaAWS <gilboabg@amazon.com> Co-authored-by: Ubuntu <ubuntu@ip-172-31-41-43.eu-west-1.compute.internal> Co-authored-by: Adar Ovadia <adarov@amazon.com> Co-authored-by: Shoham Elias <116083498+shohamazon@users.noreply.github.com> Co-authored-by: Chloe Yip <168601573+cyip10@users.noreply.github.com> * SPOTLESS Signed-off-by: Andrew Carbonetto <andrew.carbonetto@improving.com> * Fix merge conflicts Signed-off-by: Andrew Carbonetto <andrew.carbonetto@improving.com> * Review comments Signed-off-by: Andrew Carbonetto <andrew.carbonetto@improving.com> * Update docs for review comments Signed-off-by: Andrew Carbonetto <andrew.carbonetto@improving.com> * small doc fix Signed-off-by: Andrew Carbonetto <andrew.carbonetto@improving.com> --------- Signed-off-by: Andrew Carbonetto <andrew.carbonetto@improving.com> Co-authored-by: Aaron <69273634+aaron-congo@users.noreply.github.com> Co-authored-by: tjzhang-BQ <111323543+tjzhang-BQ@users.noreply.github.com> Co-authored-by: TJ Zhang <tj.zhang@improving.com> Co-authored-by: Yi-Pin Chen <yi-pin.chen@improving.com> Co-authored-by: Shoham Elias <shohame@amazon.com> Co-authored-by: jonathanl-bq <72158117+jonathanl-bq@users.noreply.github.com> Co-authored-by: James Duong <duong.james@gmail.com> Co-authored-by: Guian Gumpac <guian.gumpac@improving.com> Co-authored-by: Bar Shaul <88437685+barshaul@users.noreply.github.com> Co-authored-by: James Duong <james.duong@improving.com> Co-authored-by: James Xin <126831592+jamesx-improving@users.noreply.github.com> Co-authored-by: Jonathan Louie <jonathanl@bitquilltech.com> Co-authored-by: affonsov <affonsov@bitquilltech.com> Co-authored-by: affonsov <affonso.vieira@improving.com> Co-authored-by: Alon Arenberg <93711356+alon-arenberg@users.noreply.github.com> Co-authored-by: yulazariy <yulazari@amazon.com> Co-authored-by: Yulazari <yulazari@b0de28c93acb.ant.amazon.com> Co-authored-by: ort-bot <glide-for-redis@amazon.com> Co-authored-by: adarovadya <adarovadya@gmail.com> Co-authored-by: GilboaAWS <gilboabg@amazon.com> Co-authored-by: Ubuntu <ubuntu@ip-172-31-41-43.eu-west-1.compute.internal> Co-authored-by: Adar Ovadia <adarov@amazon.com> Co-authored-by: Shoham Elias <116083498+shohamazon@users.noreply.github.com> Co-authored-by: Chloe Yip <168601573+cyip10@users.noreply.github.com>
1 parent 885a9c4 commit 4e5c041

File tree

11 files changed

+870
-8
lines changed

11 files changed

+870
-8
lines changed

glide-core/src/client/value_conversion.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,16 @@ pub(crate) fn expected_type_for_cmd(cmd: &Cmd) -> Option<ExpectedReturnType> {
925925
key_type: &None,
926926
value_type: &None,
927927
}),
928+
b"XCLAIM" => {
929+
if cmd.position(b"JUSTID").is_some() {
930+
Some(ExpectedReturnType::ArrayOfStrings)
931+
} else {
932+
Some(ExpectedReturnType::Map {
933+
key_type: &Some(ExpectedReturnType::SimpleString),
934+
value_type: &Some(ExpectedReturnType::ArrayOfPairs),
935+
})
936+
}
937+
}
928938
b"XAUTOCLAIM" => {
929939
if cmd.position(b"JUSTID").is_some() {
930940
// Value conversion is not needed if the JUSTID arg was passed.
@@ -1262,6 +1272,36 @@ mod tests {
12621272
assert!(converted_4.is_err());
12631273
}
12641274

1275+
#[test]
1276+
fn convert_xclaim() {
1277+
assert!(matches!(
1278+
expected_type_for_cmd(
1279+
redis::cmd("XCLAIM")
1280+
.arg("key")
1281+
.arg("grou")
1282+
.arg("consumer")
1283+
.arg("0")
1284+
.arg("id")
1285+
),
1286+
Some(ExpectedReturnType::Map {
1287+
key_type: &Some(ExpectedReturnType::SimpleString),
1288+
value_type: &Some(ExpectedReturnType::ArrayOfPairs),
1289+
})
1290+
));
1291+
assert!(matches!(
1292+
expected_type_for_cmd(
1293+
redis::cmd("XCLAIM")
1294+
.arg("key")
1295+
.arg("grou")
1296+
.arg("consumer")
1297+
.arg("0")
1298+
.arg("id")
1299+
.arg("JUSTID")
1300+
),
1301+
Some(ExpectedReturnType::ArrayOfStrings)
1302+
));
1303+
}
1304+
12651305
#[test]
12661306
fn convert_xrange_xrevrange() {
12671307
assert!(matches!(

glide-core/src/protobuf/redis_request.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ enum RequestType {
243243
HScan = 202;
244244
XAutoClaim = 203;
245245
Wait = 208;
246+
XClaim = 209;
246247
}
247248

248249
message Command {

glide-core/src/request_type.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ pub enum RequestType {
213213
HScan = 202,
214214
XAutoClaim = 203,
215215
Wait = 208,
216+
XClaim = 209,
216217
}
217218

218219
fn get_two_word_command(first: &str, second: &str) -> Cmd {
@@ -429,6 +430,7 @@ impl From<::protobuf::EnumOrUnknown<ProtobufRequestType>> for RequestType {
429430
ProtobufRequestType::HScan => RequestType::HScan,
430431
ProtobufRequestType::XAutoClaim => RequestType::XAutoClaim,
431432
ProtobufRequestType::Wait => RequestType::Wait,
433+
ProtobufRequestType::XClaim => RequestType::XClaim,
432434
}
433435
}
434436
}
@@ -643,6 +645,7 @@ impl RequestType {
643645
RequestType::HScan => Some(cmd("HSCAN")),
644646
RequestType::XAutoClaim => Some(cmd("XAUTOCLAIM")),
645647
RequestType::Wait => Some(cmd("WAIT")),
648+
RequestType::XClaim => Some(cmd("XCLAIM")),
646649
}
647650
}
648651
}

java/client/src/main/java/glide/api/BaseClient.java

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import static glide.api.models.commands.bitmap.BitFieldOptions.BitFieldReadOnlySubCommands;
77
import static glide.api.models.commands.bitmap.BitFieldOptions.BitFieldSubCommands;
88
import static glide.api.models.commands.bitmap.BitFieldOptions.createBitFieldArgs;
9+
import static glide.api.models.commands.stream.StreamClaimOptions.JUST_ID_REDIS_API;
910
import static glide.ffi.resolvers.SocketListenerResolver.getSocket;
1011
import static glide.utils.ArrayTransformUtils.cast3DArray;
1112
import static glide.utils.ArrayTransformUtils.castArray;
@@ -137,6 +138,7 @@
137138
import static redis_request.RedisRequestOuterClass.RequestType.Watch;
138139
import static redis_request.RedisRequestOuterClass.RequestType.XAck;
139140
import static redis_request.RedisRequestOuterClass.RequestType.XAdd;
141+
import static redis_request.RedisRequestOuterClass.RequestType.XClaim;
140142
import static redis_request.RedisRequestOuterClass.RequestType.XDel;
141143
import static redis_request.RedisRequestOuterClass.RequestType.XGroupCreate;
142144
import static redis_request.RedisRequestOuterClass.RequestType.XGroupCreateConsumer;
@@ -226,6 +228,7 @@
226228
import glide.api.models.commands.scan.SScanOptions;
227229
import glide.api.models.commands.scan.ZScanOptions;
228230
import glide.api.models.commands.stream.StreamAddOptions;
231+
import glide.api.models.commands.stream.StreamClaimOptions;
229232
import glide.api.models.commands.stream.StreamGroupOptions;
230233
import glide.api.models.commands.stream.StreamPendingOptions;
231234
import glide.api.models.commands.stream.StreamRange;
@@ -2178,6 +2181,66 @@ public CompletableFuture<Object[][]> xpending(
21782181
XPending, args, response -> castArray(handleArrayResponse(response), Object[].class));
21792182
}
21802183

2184+
@Override
2185+
public CompletableFuture<Map<String, String[][]>> xclaim(
2186+
@NonNull String key,
2187+
@NonNull String group,
2188+
@NonNull String consumer,
2189+
long minIdleTime,
2190+
@NonNull String[] ids) {
2191+
String[] args =
2192+
concatenateArrays(new String[] {key, group, consumer, Long.toString(minIdleTime)}, ids);
2193+
return commandManager.submitNewCommand(XClaim, args, this::handleMapResponse);
2194+
}
2195+
2196+
@Override
2197+
public CompletableFuture<Map<String, String[][]>> xclaim(
2198+
@NonNull String key,
2199+
@NonNull String group,
2200+
@NonNull String consumer,
2201+
long minIdleTime,
2202+
@NonNull String[] ids,
2203+
@NonNull StreamClaimOptions options) {
2204+
String[] args =
2205+
concatenateArrays(
2206+
new String[] {key, group, consumer, Long.toString(minIdleTime)}, ids, options.toArgs());
2207+
return commandManager.submitNewCommand(XClaim, args, this::handleMapResponse);
2208+
}
2209+
2210+
@Override
2211+
public CompletableFuture<String[]> xclaimJustId(
2212+
@NonNull String key,
2213+
@NonNull String group,
2214+
@NonNull String consumer,
2215+
long minIdleTime,
2216+
@NonNull String[] ids) {
2217+
String[] args =
2218+
concatenateArrays(
2219+
new String[] {key, group, consumer, Long.toString(minIdleTime)},
2220+
ids,
2221+
new String[] {JUST_ID_REDIS_API});
2222+
return commandManager.submitNewCommand(
2223+
XClaim, args, response -> castArray(handleArrayResponse(response), String.class));
2224+
}
2225+
2226+
@Override
2227+
public CompletableFuture<String[]> xclaimJustId(
2228+
@NonNull String key,
2229+
@NonNull String group,
2230+
@NonNull String consumer,
2231+
long minIdleTime,
2232+
@NonNull String[] ids,
2233+
@NonNull StreamClaimOptions options) {
2234+
String[] args =
2235+
concatenateArrays(
2236+
new String[] {key, group, consumer, Long.toString(minIdleTime)},
2237+
ids,
2238+
options.toArgs(),
2239+
new String[] {JUST_ID_REDIS_API});
2240+
return commandManager.submitNewCommand(
2241+
XClaim, args, response -> castArray(handleArrayResponse(response), String.class));
2242+
}
2243+
21812244
@Override
21822245
public CompletableFuture<Long> pttl(@NonNull String key) {
21832246
return commandManager.submitNewCommand(PTTL, new String[] {key}, this::handleLongResponse);

java/client/src/main/java/glide/api/commands/StreamBaseCommands.java

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import glide.api.models.GlideString;
55
import glide.api.models.commands.stream.StreamAddOptions;
66
import glide.api.models.commands.stream.StreamAddOptions.StreamAddOptionsBuilder;
7+
import glide.api.models.commands.stream.StreamClaimOptions;
78
import glide.api.models.commands.stream.StreamGroupOptions;
89
import glide.api.models.commands.stream.StreamPendingOptions;
910
import glide.api.models.commands.stream.StreamRange;
@@ -711,4 +712,119 @@ CompletableFuture<Object[][]> xpending(
711712
StreamRange end,
712713
long count,
713714
StreamPendingOptions options);
715+
716+
/**
717+
* Changes the ownership of a pending message.
718+
*
719+
* @see <a href="https://valkey.io/commands/xclaim/">valkey.io</a> for details.
720+
* @param key The key of the stream.
721+
* @param group The consumer group name.
722+
* @param consumer The group consumer.
723+
* @param minIdleTime The minimum idle time for the message to be claimed.
724+
* @param ids A array of entry ids.
725+
* @return A <code>Map</code> of message entries with the format <code>
726+
* {"entryId": [["entry", "data"], ...], ...}</code> that are claimed by the consumer.
727+
* @example
728+
* <pre>
729+
* // read messages from streamId for consumer1
730+
* var readResult = client.xreadgroup(Map.of("mystream", ">"), "mygroup", "consumer1").get();
731+
* // "entryId" is now read, and we can assign the pending messages to consumer2
732+
* Map<String, String[][]> results = client.xclaim("mystream", "mygroup", "consumer2", 0L, new String[] {entryId}).get();
733+
* for (String key: results.keySet()) {
734+
* System.out.println(key);
735+
* for (String[] entry: results.get(key)) {
736+
* System.out.printf("{%s=%s}%n", entry[0], entry[1]);
737+
* }
738+
* }
739+
* </pre>
740+
*/
741+
CompletableFuture<Map<String, String[][]>> xclaim(
742+
String key, String group, String consumer, long minIdleTime, String[] ids);
743+
744+
/**
745+
* Changes the ownership of a pending message.
746+
*
747+
* @see <a href="https://valkey.io/commands/xclaim/">valkey.io</a> for details.
748+
* @param key The key of the stream.
749+
* @param group The consumer group name.
750+
* @param consumer The group consumer.
751+
* @param minIdleTime The minimum idle time for the message to be claimed.
752+
* @param ids An array of entry ids.
753+
* @param options Stream claim options {@link StreamClaimOptions}.
754+
* @return A <code>Map</code> of message entries with the format <code>
755+
* {"entryId": [["entry", "data"], ...], ...}</code> that are claimed by the consumer.
756+
* @example
757+
* <pre>
758+
* // assign (force) unread and unclaimed messages to consumer2
759+
* StreamClaimOptions options = StreamClaimOptions.builder().force().build();
760+
* Map<String, String[][]> results = client.xclaim("mystream", "mygroup", "consumer2", 0L, new String[] {entryId}, options).get();
761+
* for (String key: results.keySet()) {
762+
* System.out.println(key);
763+
* for (String[] entry: results.get(key)) {
764+
* System.out.printf("{%s=%s}%n", entry[0], entry[1]);
765+
* }
766+
* }
767+
* </pre>
768+
*/
769+
CompletableFuture<Map<String, String[][]>> xclaim(
770+
String key,
771+
String group,
772+
String consumer,
773+
long minIdleTime,
774+
String[] ids,
775+
StreamClaimOptions options);
776+
777+
/**
778+
* Changes the ownership of a pending message. This function returns an <code>array</code> with
779+
* only the message/entry IDs, and is equivalent to using <code>JUSTID</code> in the Redis API.
780+
*
781+
* @see <a href="https://valkey.io/commands/xclaim/">valkey.io</a> for details.
782+
* @param key The key of the stream.
783+
* @param group The consumer group name.
784+
* @param consumer The group consumer.
785+
* @param minIdleTime The minimum idle time for the message to be claimed.
786+
* @param ids An array of entry ids.
787+
* @return An <code>array</code> of message ids claimed by the consumer.
788+
* @example
789+
* <pre>
790+
* // read messages from streamId for consumer1
791+
* var readResult = client.xreadgroup(Map.of("mystream", ">"), "mygroup", "consumer1").get();
792+
* // "entryId" is now read, and we can assign the pending messages to consumer2
793+
* String[] results = client.xclaimJustId("mystream", "mygroup", "consumer2", 0L, new String[] {entryId}).get();
794+
* for (String id: results) {
795+
* System.out.printf("consumer2 claimed stream entry ID: %s %n", id);
796+
* }
797+
* </pre>
798+
*/
799+
CompletableFuture<String[]> xclaimJustId(
800+
String key, String group, String consumer, long minIdleTime, String[] ids);
801+
802+
/**
803+
* Changes the ownership of a pending message. This function returns an <code>array</code> with
804+
* only the message/entry IDs, and is equivalent to using <code>JUSTID</code> in the Redis API.
805+
*
806+
* @see <a href="https://valkey.io/commands/xclaim/">valkey.io</a> for details.
807+
* @param key The key of the stream.
808+
* @param group The consumer group name.
809+
* @param consumer The group consumer.
810+
* @param minIdleTime The minimum idle time for the message to be claimed.
811+
* @param ids An array of entry ids.
812+
* @param options Stream claim options {@link StreamClaimOptions}.
813+
* @return An <code>array</code> of message ids claimed by the consumer.
814+
* @example
815+
* <pre>
816+
* // assign (force) unread and unclaimed messages to consumer2
817+
* StreamClaimOptions options = StreamClaimOptions.builder().force().build();
818+
* String[] results = client.xclaimJustId("mystream", "mygroup", "consumer2", 0L, new String[] {entryId}, options).get();
819+
* for (String id: results) {
820+
* System.out.printf("consumer2 claimed stream entry ID: %s %n", id);
821+
* }
822+
*/
823+
CompletableFuture<String[]> xclaimJustId(
824+
String key,
825+
String group,
826+
String consumer,
827+
long minIdleTime,
828+
String[] ids,
829+
StreamClaimOptions options);
714830
}

0 commit comments

Comments
 (0)