Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HGETDEL, HGETEX and HSETEX hash commands #3204

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

ggivo
Copy link
Contributor

@ggivo ggivo commented Mar 7, 2025

This PR adds support for three new hash commands: HGETDEL, HGETEX and HSETEX. These commands enable user to do multiple operations in one step atomically e.g. set a hash field and update its TTL with a single command.

  • HGETDEL
  • HGETEX
  • HSETEX

Make sure that:

  • You have read the contribution guidelines.
  • You have created a feature request first to discuss your contribution intent. Please reference the feature request ticket number in the pull request.
  • You applied code formatting rules using the mvn formatter:format target. Don’t submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes.

Closes #3195

@ggivo ggivo requested review from tishun and Copilot March 7, 2025 08:59
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Overview

This PR adds support for three new hash commands—HGETDEL, HGETEX, and HSETEX—to enable atomic operations combining field updates with expiry management. Key changes include:

  • Introducing new argument builder classes (HGetExArgs and HSetExArgs) for handling expiration and persistence options.
  • Extending synchronous, asynchronous, and reactive APIs with new methods and updating the command builder accordingly.
  • Adding new integration and unit tests to validate the behavior of the new commands.

Reviewed Changes

File Description
src/main/java/io/lettuce/core/HGetExArgs.java New builder class for HGETEX arguments with expiry and persistence.
src/main/java/io/lettuce/core/api/async/RedisHashAsyncCommands.java Added HGETDEL, HGETEX, and HSETEX method signatures for async commands.
src/main/templates/io/lettuce/core/api/RedisHashCommands.java Extended synchronous command template with new hash commands.
src/main/java/io/lettuce/core/api/reactive/RedisHashReactiveCommands.java Added reactive APIs for new commands.
src/main/java/io/lettuce/core/cluster/api/sync/NodeSelectionHashCommands.java Extended cluster sync API with new hash commands.
src/main/java/io/lettuce/core/cluster/api/async/NodeSelectionHashAsyncCommands.java Extended cluster async API with new hash commands.
src/test/java/io/lettuce/core/commands/HashCommandIntegrationTests.java Introduced new integration tests covering the new commands.
src/main/java/io/lettuce/core/RedisCommandBuilder.java Updated command builder to support HSETEX and HGETEX construction.
src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java Updated reactive command implementations for new commands.
src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java Updated async command implementations for new commands.
src/main/java/io/lettuce/core/protocol/CommandKeyword.java Minor update to include additional keywords.
src/main/java/io/lettuce/core/protocol/CommandType.java Extended CommandType enum with HGETDEL, HSETEX, and HGETEX.

Copilot reviewed 17 out of 17 changed files in this pull request and generated 1 comment.

Copy link
Collaborator

@tishun tishun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM generally, only a few things you could address

* {@link HGetExArgs} is a mutable object and instances should be used only once to avoid shared mutable state.
*
* @author Ivo Gaydajiev
* @since 6.7.0
Copy link
Collaborator

@tishun tishun Mar 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we change this to 6.6 (everywhere)

6.7 is not yet planned and we need to release this soon
also we usually do not put patch release, because no new functionality is added in patch releases

Copy link
Contributor Author

@ggivo ggivo Mar 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do. 6.7 is the current snapshot version in the pom. So I thought this would be the next release version.


LettuceAssert.notNull(timeout, "Timeout must not be null");

this.ex = timeout.toMillis() / 1000;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using getSeconds() I think is the same


LettuceAssert.notNull(timestamp, "Timestamp must not be null");

return exAt(timestamp.toEpochMilli() / 1000);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getEpochSecond() should be the same I think

* @return new {@link HGetExArgs} with {@literal EX} enabled.
* @see HGetExArgs#ex(long)
*/
public static HGetExArgs ex(long timeout) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO we should only use Duration and Instant for newly introduced APIs.

The long and Date approaches are no longer the best way to handle timeframes.

This goes for all classes and all methods, not only this one.

   - @SInCE 6.7.0 -> 6.6
   - Remove long/Date methods for settin timestamp
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.

Hash Field Expiration (part II)
2 participants