Skip to content

Hash Field Expiration (part II) (#3195) #3204

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

Merged
merged 9 commits into from
Mar 24, 2025
Merged

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.

Copy link
Collaborator

Choose a reason for hiding this comment

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

6.7 is the current snapshot version in the pom.

Yeah ... well this is unfortunately a mistake :(


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
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.

You only need to fix the unit test, as shown below:

ggivo and others added 2 commits March 10, 2025 13:01
@tishun tishun changed the title Add HGETDEL, HGETEX and HSETEX hash commands Hash Field Expiration (part II) (#3195) Mar 18, 2025
@tishun tishun merged commit 3800095 into redis:main Mar 24, 2025
7 checks passed
svc-squareup-copybara pushed a commit to cashapp/misk that referenced this pull request Jun 3, 2025
| Package | Type | Package file | Manager | Update | Change |
|---|---|---|---|---|---|
| [io.lettuce:lettuce-core](https://github.com/redis/lettuce) |
dependencies | misk/gradle/libs.versions.toml | gradle | minor |
`6.5.5.RELEASE` -> `6.7.0.RELEASE` |

---

### Release Notes

<details>
<summary>redis/lettuce (io.lettuce:lettuce-core)</summary>

###
[`v6.7.0.RELEASE`](https://github.com/redis/lettuce/releases/tag/6.7.0.RELEASE)

[Compare
Source](redis/lettuce@6.6.0.RELEASE...6.7.0.RELEASE)

The Lettuce team is pleased to announce the Lettuce 6.7.0 minor release!

This release provides support for the newly introduced [Vector
Sets](https://redis.io/docs/latest/develop/data-types/vector-sets/) data
type which was released as part of Redis 8.0 and [helps Redis users with
vector
similarity](https://redis.io/blog/announcing-vector-sets-a-new-redis-data-type-for-vector-similarity/).

Starting with 6.7 the `ConnectionPoolSupport` also provides a way to
provide custom connection validations. The release comes with a bunch of
smaller improvements and bugfixes.

Lettuce 6.7.0 supports Redis 2.6+ up to Redis 8.x. In terms of Java
runtime, Lettuce requires at least Java 8 and
works with Java 24. The driver is tested against Redis 8.0, Redis 7.4
and Redis 7.2.

Find the full changelog at the end of this document.
Thanks to all contributors who made Lettuce 6.7.0.RELEASE possible.

#### 📗 Links

- Reference documentation:
https://lettuce.io/core/6.7.0.RELEASE/reference/
-   Javadoc: https://lettuce.io/core/6.7.0.RELEASE/api/

#### ⭐ New Features

- Support Redis 8 vector sets
[#&#8203;3296](redis/lettuce#3296) by
[@&#8203;tishun](https://github.com/tishun) in
redis/lettuce#3295
- Add custom connection validation to ConnectionPoolSupport
[#&#8203;3081](redis/lettuce#3081) by
[@&#8203;big-cir](https://github.com/big-cir) in
redis/lettuce#3138

#### 🐞 Bug Fixes

- Fix deadlock when an invalid URI is presented to
DefaultClusterTopologyRefresh by
[@&#8203;henry701](https://github.com/henry701) in
redis/lettuce#3243
- Fix NPE in EntraIdIntegrationTests by
[@&#8203;ggivo](https://github.com/ggivo) in
redis/lettuce#3254
- Deprecate DnsResolver in favor of
AddressResolverGroup([#&#8203;1572](redis/lettuce#1572))
by [@&#8203;young0264](https://github.com/young0264) in
redis/lettuce#3291

#### 💡 Other

- Change native library default to epoll over io_uring by
[@&#8203;thachlp](https://github.com/thachlp) in
redis/lettuce#3278
- Use InfoPatterns enum for ReplicaTopologyProvider pattern management
by [@&#8203;ori0o0p](https://github.com/ori0o0p) in
redis/lettuce#3264
- Adjusting disconnectedBehavior Option to Prevent Timeout During Redis
Shutdown [#&#8203;2866](redis/lettuce#2866) by
[@&#8203;MagicalLas](https://github.com/MagicalLas) in
redis/lettuce#2894
- Improve the performance of obtaining write connections through
double-check locks. by
[@&#8203;Chenrujie-85](https://github.com/Chenrujie-85) in
redis/lettuce#3228
- Optimize string concatenation in
NodeSelectionInvocationHandler.getNodeDescription() by
[@&#8203;ori0o0p](https://github.com/ori0o0p) in
redis/lettuce#3262
- DOC-4756 sorted set examples with join() by
[@&#8203;andy-stark-redis](https://github.com/andy-stark-redis) in
redis/lettuce#3184
- DOC-4757 list examples using join() by
[@&#8203;andy-stark-redis](https://github.com/andy-stark-redis) in
redis/lettuce#3185
- docs: add default threads count about NioEventLoopGroup by
[@&#8203;brido4125](https://github.com/brido4125) in
redis/lettuce#3221
- Guide on resolving native library conflicts by
[@&#8203;thachlp](https://github.com/thachlp) in
redis/lettuce#3309

#### ❤️  New Contributors

- [@&#8203;big-cir](https://github.com/big-cir) made their first
contribution in redis/lettuce#3138
- [@&#8203;Chenrujie-85](https://github.com/Chenrujie-85) made their
first contribution in redis/lettuce#3228
- [@&#8203;brido4125](https://github.com/brido4125) made their first
contribution in redis/lettuce#3221
- [@&#8203;MagicalLas](https://github.com/MagicalLas) made their first
contribution in redis/lettuce#2894
- [@&#8203;young0264](https://github.com/young0264) made their first
contribution in redis/lettuce#3291
- [@&#8203;henry701](https://github.com/henry701) made their first
contribution in redis/lettuce#3243

**Full Changelog**:
redis/lettuce@6.6.0.BETA4...6.7.0.RELEASE

###
[`v6.6.0.RELEASE`](https://github.com/redis/lettuce/releases/tag/6.6.0.RELEASE)

[Compare
Source](redis/lettuce@6.5.5.RELEASE...6.6.0.RELEASE)

The Lettuce team is pleased to announce the Lettuce 6.6.0 minor release!

This release provides support for the newly introduced `HGETDEL`,
`HGETEX` and `HSETEX` commands.
Users of the driver are also now able to [use a command replay
filter](https://redis.github.io/lettuce/advanced-usage/#controlling-replay-of-commands-in-at-lease-once-mode),
that allows the user to control which (if any) commands are being
retried when the reconnect feature is on. It is also possible to
configure the driver to use the `HashIndexedQueue` as a backing data
structure for the command queue, which speeds up the driver during
disconnect / reconnect (needs to be configured using the ClientOptions).

The driver comes with Microsoft EntraID authentication support.

Last but not least the `STRALGO` command was replaced by the `LCS`
command.

Lettuce 6.6.0 supports Redis 2.6+ up to Redis 8.x. In terms of Java
runtime, Lettuce requires at least Java 8 and
works with Java 24. The driver is tested against Redis 8.0, Redis 7.4
and Redis 7.2.

Find the full changelog at the end of this document.
Thanks to all contributors who made Lettuce 6.6.0.RELEASE possible.

#### 📗 Links

- Reference documentation:
https://lettuce.io/core/6.6.0.RELEASE/reference/
-   Javadoc: https://lettuce.io/core/6.6.0.RELEASE/api/

#### ⭐ New Features

- Hash Field Expiration (part II)
([#&#8203;3195](redis/lettuce#3195)) by
[@&#8203;ggivo](https://github.com/ggivo) in
redis/lettuce#3204
- Introduce command replay filter to avoid command replaying after
reconnect [#&#8203;1310](redis/lettuce#1310)
by [@&#8203;tishun](https://github.com/tishun) in
redis/lettuce#3118
- Deprecate the STRALGO command and implement the LCS in its place by
[@&#8203;Dltmd202](https://github.com/Dltmd202) in
redis/lettuce#3037
- fix: prevent blocking event loop thread by replacing ArrayDeque with
HashIndexedQueue by [@&#8203;okg-cxf](https://github.com/okg-cxf) in
redis/lettuce#2953
- Token based authentication integration with core extension by
[@&#8203;ggivo](https://github.com/ggivo) in
redis/lettuce#3063
- Support for DefaultAzureCredential by
[@&#8203;ggivo](https://github.com/ggivo) in
redis/lettuce#3230
- Add support up to max unsigned integer in Bitfield offset
([#&#8203;2964](redis/lettuce#2964)) by
[@&#8203;psw0946](https://github.com/psw0946) in
redis/lettuce#3099
- Improve code by adding some null checks by
[@&#8203;tishun](https://github.com/tishun) in
redis/lettuce#3115
- Introduce test matrix based on Redis server versions by
[@&#8203;ggivo](https://github.com/ggivo) in
redis/lettuce#3145
- Add modules ACL support by
[@&#8203;sazzad16](https://github.com/sazzad16) in
redis/lettuce#3102
- Test modules CONFIG support by
[@&#8203;sazzad16](https://github.com/sazzad16) in
redis/lettuce#3103
- report block error when use with reactor mode
[#&#8203;3168](redis/lettuce#3168) by
[@&#8203;tishun](https://github.com/tishun) in
redis/lettuce#3169
- Include command type in the timeout message by
[@&#8203;arturaz](https://github.com/arturaz) in
redis/lettuce#3167
- replace hardcoded GT and LT with CommandKeyword enum by
[@&#8203;minwoo1999](https://github.com/minwoo1999) in
redis/lettuce#3079

#### 🐞 Bug Fixes

- Restore API that was accidently deleted when introducing the JSON
feature by [@&#8203;tishun](https://github.com/tishun) in
redis/lettuce#3065
- Propagate handshake failures to Handshake future by
[@&#8203;mp911de](https://github.com/mp911de) in
redis/lettuce#3058
- OpsForGeo producing "READONLY You can't write against a read only
replica " on READS... by [@&#8203;ggivo](https://github.com/ggivo) in
redis/lettuce#3032
- Json commands not exposed in AsyncCluster
[#&#8203;3048](redis/lettuce#3048) by
[@&#8203;tishun](https://github.com/tishun) in
redis/lettuce#3049
- WATCH during MULTI shouldn't fail transaction
[#&#8203;3009](redis/lettuce#3009) by
[@&#8203;tishun](https://github.com/tishun) in
redis/lettuce#3027
- Fix: make sure FIFO order between write and notify channel active by
[@&#8203;okg-cxf](https://github.com/okg-cxf) in
redis/lettuce#2597
- UnsupportedOperationException from ListSubscriber during
hrandfieldWithvalues
[#&#8203;3122](redis/lettuce#3122) by
[@&#8203;tishun](https://github.com/tishun) in
redis/lettuce#3123
- Update CommonsPool2ConfigConverterUnitTests.java by
[@&#8203;Rian-Ismael](https://github.com/Rian-Ismael) in
redis/lettuce#3147
- Fix typo & add withSsl() in connecting to Entra ID enabled Redis doc
by [@&#8203;ggivo](https://github.com/ggivo) in
redis/lettuce#3191
- Fix SimpleBatcher apparent deadlock
[#&#8203;2196](redis/lettuce#2196) by
[@&#8203;ggivo](https://github.com/ggivo) in
redis/lettuce#3148
- jsonArrpop fails with null return value
([#&#8203;3196](redis/lettuce#3196)) by
[@&#8203;tishun](https://github.com/tishun) in
redis/lettuce#3206
- json.arrpop forces index=-1 with root path
([#&#8203;3214](redis/lettuce#3214)) by
[@&#8203;thachlp](https://github.com/thachlp) in
redis/lettuce#3217
- Updates enableAdaptiveRefreshTrigger trigger assertion message by
[@&#8203;ymiliaresis](https://github.com/ymiliaresis) in
redis/lettuce#3216

#### 💡 Other

- Add example configuration using SNI enabled TLS connection by
[@&#8203;ggivo](https://github.com/ggivo) in
redis/lettuce#3045
- Disable docker image being used to call compose when running tests by
[@&#8203;tishun](https://github.com/tishun) in
redis/lettuce#3046
- Workflow for running benchmarks weekly by
[@&#8203;tishun](https://github.com/tishun) in
redis/lettuce#3052
- Fixing benchmark flow by [@&#8203;tishun](https://github.com/tishun)
in redis/lettuce#3056
- Test failures not reported because step is skipped by
[@&#8203;tishun](https://github.com/tishun) in
redis/lettuce#3067
- Stale issues action bump by
[@&#8203;tishun](https://github.com/tishun) in
redis/lettuce#3182
- Migrate Lettuce test setup to use client-lib-test by
[@&#8203;kiryazovi-redis](https://github.com/kiryazovi-redis) in
redis/lettuce#3158
- JSON integration tests now do not use the test-containers framework by
[@&#8203;tishun](https://github.com/tishun) in
redis/lettuce#3203
- Test with 8.0-M05-pre by [@&#8203;ggivo](https://github.com/ggivo) in
redis/lettuce#3219
- Add sample examples to test redis.io build by
[@&#8203;uglide](https://github.com/uglide) in
redis/lettuce#3051
- DOC-4528 async hash examples by
[@&#8203;andy-stark-redis](https://github.com/andy-stark-redis) in
redis/lettuce#3069
- DOC-4531 set data type examples by
[@&#8203;andy-stark-redis](https://github.com/andy-stark-redis) in
redis/lettuce#3076
- DOC-4802 fix string example concurrency by
[@&#8203;andy-stark-redis](https://github.com/andy-stark-redis) in
redis/lettuce#3156
- Fix several typos on the advanced-usage page by
[@&#8203;danicheg](https://github.com/danicheg) in
redis/lettuce#3174
- docs: update Limitations section to reflect shaded JAR deprecation by
[@&#8203;minwoo1999](https://github.com/minwoo1999) in
redis/lettuce#3095
- Remove extra spaces in words in docs by
[@&#8203;enjoy-binbin](https://github.com/enjoy-binbin) in
redis/lettuce#3120
- Bump to v4 of checkout by [@&#8203;tishun](https://github.com/tishun)
in redis/lettuce#3152
- Fix 'make test' test failures by
[@&#8203;ggivo](https://github.com/ggivo) in
redis/lettuce#3157
- Readme doc on how to connect to Azure Managed Redis with Entra ID
authentication by [@&#8203;ggivo](https://github.com/ggivo) in
redis/lettuce#3166
- refactor mget method improved readability and efficiency by
[@&#8203;ori0o0p](https://github.com/ori0o0p) in
redis/lettuce#3061
- Migrate JSON tests infra to use client-lilb-test by
[@&#8203;ggivo](https://github.com/ggivo) in
redis/lettuce#3128
- Update the base project URLs in pom.xml by
[@&#8203;danicheg](https://github.com/danicheg) in
redis/lettuce#3151
- Update publish docs action to use latest versions of actions by
[@&#8203;tishun](https://github.com/tishun) in
redis/lettuce#3154
- Bump default client-libs-test container version by
[@&#8203;ggivo](https://github.com/ggivo) in
redis/lettuce#3165
- Bump org.slf4j:jcl-over-slf4j from 1.7.25 to 2.0.16 by
[@&#8203;dependabot](https://github.com/dependabot) in
redis/lettuce#2959
- Bump org.testcontainers:testcontainers from 1.20.1 to 1.20.4 by
[@&#8203;dependabot](https://github.com/dependabot) in
redis/lettuce#3082
- Bump io.micrometer:micrometer-bom from 1.12.4 to 1.14.2 by
[@&#8203;dependabot](https://github.com/dependabot) in
redis/lettuce#3096
- Bump io.netty.incubator:netty-incubator-transport-native-io_uring from
0.0.25.Final to 0.0.26.Final by
[@&#8203;dependabot](https://github.com/dependabot) in
redis/lettuce#3106
- Bump netty.version to 4.1.118.Final
[#&#8203;3187](redis/lettuce#3187) by
[@&#8203;tishun](https://github.com/tishun) in
redis/lettuce#3189

#### ❤️  New Contributors

- [@&#8203;Dltmd202](https://github.com/Dltmd202) made their first
contribution in redis/lettuce#3037
- [@&#8203;andy-stark-redis](https://github.com/andy-stark-redis) made
their first contribution in redis/lettuce#3069
- [@&#8203;okg-cxf](https://github.com/okg-cxf) made their first
contribution in redis/lettuce#2953
- [@&#8203;minwoo1999](https://github.com/minwoo1999) made their first
contribution in redis/lettuce#3079
- [@&#8203;psw0946](https://github.com/psw0946) made their first
contribution in redis/lettuce#3099
- [@&#8203;ori0o0p](https://github.com/ori0o0p) made their first
contribution in redis/lettuce#3061
- [@&#8203;enjoy-binbin](https://github.com/enjoy-binbin) made their
first contribution in redis/lettuce#3120
- [@&#8203;sazzad16](https://github.com/sazzad16) made their first
contribution in redis/lettuce#3102
- [@&#8203;danicheg](https://github.com/danicheg) made their first
contribution in redis/lettuce#3151
- [@&#8203;Rian-Ismael](https://github.com/Rian-Ismael) made their first
contribution in redis/lettuce#3147
- [@&#8203;kiryazovi-redis](https://github.com/kiryazovi-redis) made
their first contribution in redis/lettuce#3158
- [@&#8203;ymiliaresis](https://github.com/ymiliaresis) made their first
contribution in redis/lettuce#3216
- [@&#8203;arturaz](https://github.com/arturaz) made their first
contribution in redis/lettuce#3167

**Full Changelog**:
redis/lettuce@6.5.0.RELEASE...6.6.0.RELEASE

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "after 6pm every weekday,before 2am
every weekday" in timezone Australia/Melbourne, Automerge - At any time
(no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Never, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Renovate
Bot](https://github.com/renovatebot/renovate).

GitOrigin-RevId: f67609a2c7de516500eacfa74f5c061609b8eff7
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