Skip to content

Conversation

@Sasidharan3094
Copy link
Contributor

@Sasidharan3094 Sasidharan3094 commented Dec 28, 2025

Add support for KEYS, MIGRATE, and WAITAOF commands in Java client

This fixes the issue

Description

This PR adds support for three Redis/Valkey commands to the Java client:

  • KEYS - Returns all keys matching a pattern
  • MIGRATE - Atomically transfers a key from source to destination instance
  • WAITAOF - Blocks until writes are acknowledged by local and remote replicas

Changes Made

1. KEYS Command

  • Added keys(String pattern) and keys(GlideString pattern) to GenericBaseCommands interface
  • Implemented in BaseClient for standalone mode
  • Implemented in GlideClusterClient for cluster mode (routes to all primary nodes)
  • Returns array of keys matching the pattern

2. MIGRATE Command

  • Added migrate(String host, long port, String key, long destinationDB, long timeout) to GenericBaseCommands interface
  • Added migrate(String host, long port, GlideString key, long destinationDB, long timeout) variant
  • Added overloaded methods with MigrateOptions parameter for COPY, REPLACE, AUTH, and AUTH2 options
  • Created MigrateOptions model class with builder pattern
  • Implemented in both BaseClient and GlideClusterClient
  • Returns "OK" on success or "NOKEY" if key doesn't exist

3. WAITAOF Command

  • Added waitaof(long numlocal, long numreplicas, long timeout) to GenericBaseCommands interface
  • Implemented in both BaseClient and GlideClusterClient
  • Returns Long[] array with [local_acks, replica_acks]
  • Routes to random node in cluster mode

Files Modified

  • java/client/src/main/java/glide/api/commands/GenericBaseCommands.java - Added interface methods
  • java/client/src/main/java/glide/api/BaseClient.java - Added implementations
  • java/client/src/main/java/glide/api/GlideClusterClient.java - Added cluster implementations

Files Created

  • java/client/src/main/java/glide/api/models/commands/MigrateOptions.java - Options class for MIGRATE command

Implementation Details

  • Added WaitAof, Keys, and Migrate imports to both client classes
  • Used existing patterns from similar commands (e.g., wait()) as reference
  • All methods include comprehensive JavaDoc documentation with examples
  • Supports both String and GlideString variants where applicable
  • MigrateOptions supports: COPY, REPLACE, AUTH (password), AUTH2 (username/password)

Testing

  • Integration tests to be added (if required by maintainers)

Checklist

  • Added method signatures to interface
  • Implemented in BaseClient
  • Implemented in GlideClusterClient
  • Added proper imports
  • Created MigrateOptions model class
  • Added JavaDoc documentation with examples
  • Code formatted and linted
  • Follows existing code patterns
  • DCO signoff included in commits

Additional Notes

  • WAITAOF requires Valkey 7.2 or above
  • KEYS command in cluster mode routes to all primary nodes and combines results
  • MIGRATE supports optional parameters via MigrateOptions for advanced use cases but it requires all keys to be present in Same SLOT or else we will get CROSSSLOT errors in cluster mode.

@Sasidharan3094 Sasidharan3094 requested a review from a team as a code owner December 28, 2025 14:15
Signed-off-by: Sasidharan Gopal <[email protected]>
Signed-off-by: Sasidharan Gopal <[email protected]>
Signed-off-by: Sasidharan Gopal <[email protected]>
Signed-off-by: Sasidharan Gopal <[email protected]>
Signed-off-by: Sasidharan Gopal <[email protected]>
Signed-off-by: Sasidharan Gopal <[email protected]>
@Sasidharan3094
Copy link
Contributor Author

Sasidharan3094 commented Dec 29, 2025

@yipin-chen @alexr-bq @xShinnRyuu Please review this PR and retry the failed checks as they are transient errors. Thanks.

@Sasidharan3094
Copy link
Contributor Author

@yipin-chen @alexr-bq Please review this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(Java): Implement Keys, migrate and waitaof command in java client

1 participant