Skip to content

Add Expiration-based API for SET command operations.#3305

Closed
Dgramada wants to merge 5 commits intospring-projects:mainfrom
Dgramada:topic/replace-set-command-timeunit-api-with-expiration
Closed

Add Expiration-based API for SET command operations.#3305
Dgramada wants to merge 5 commits intospring-projects:mainfrom
Dgramada:topic/replace-set-command-timeunit-api-with-expiration

Conversation

@Dgramada
Copy link
Contributor

@Dgramada Dgramada commented Feb 3, 2026

Summary

This PR introduces Expiration-based API methods for SET command operations, replacing the existing TimeUnit variants.

Motivation

The current API using TimeUnit cannot express advanced Redis SET options:

  • KEEPTTL - Preserve existing TTL when updating a value
  • Persistent - Explicitly no expiration
  • Unix Timestamp - Set expiration to absolute time (EXAT/PXAT)

The Expiration class already supports these features at the connection layer, but they were not accessible through the template API.

Changes

New Methods (with @since 4.1)

  • ValueOperations: set, setGet, setIfAbsent, setIfPresent with Expiration
  • BoundValueOperations: set, setGet, setIfAbsent, setIfPresent with Expiration
  • ReactiveValueOperations: set, setGet, setIfAbsent, setIfPresent with Expiration

Deprecated Methods

  • All TimeUnit variants marked with @Deprecated(since = "4.1", forRemoval = true)

Bug Fix

  • Fixed LettuceReactiveStringCommands.setGet() which was ignoring expiration and set options (pre-existing bug since 3.5)

Kotlin Extensions

  • Added coroutine extension functions for reactive Expiration variants

Testing

  • Added integration tests for all new methods
  • Added unit tests for Kotlin extensions

Introduce new methods accepting Expiration instead of Duration/TimeUnit
for set, setGet, setIfAbsent, and setIfPresent operations across
ValueOperations, BoundValueOperations, and ReactiveValueOperations.

Deprecate existing Duration and TimeUnit-based methods in favor of
the new Expiration-based variants.

Fix LettuceReactiveStringCommands.setGet() to properly apply expiration
and set options which were previously being ignored.

Add Kotlin coroutine extension functions for reactive Expiration variants.

Signed-off-by: Yordan Tsintsov <yordan.tsintsov@redis.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 3, 2026
Signed-off-by: Yordan Tsintsov <yordan.tsintsov@redis.com>
…o call Expiration set method instead of TimeUnit set method.

Signed-off-by: Yordan Tsintsov <yordan.tsintsov@redis.com>
…methods.

Signed-off-by: Yordan Tsintsov <yordan.tsintsov@redis.com>
@onobc onobc self-assigned this Feb 5, 2026
@onobc onobc removed the status: waiting-for-triage An issue we've not yet triaged label Feb 5, 2026
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 5, 2026
@onobc onobc removed the status: waiting-for-triage An issue we've not yet triaged label Feb 5, 2026
@onobc onobc self-requested a review February 5, 2026 20:48
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 5, 2026
Copy link
Contributor

@onobc onobc left a comment

Choose a reason for hiding this comment

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

@Dgramada this is looking good. I am in the middle of the review but I wanted to drop my current feedback before I drop off for the day so we can timezone surf...

  1. Please add yourself as @ author where applicable
  2. I think we should also deprecate the Duration variants as they suffer the same limitations as TimeUnit.
  3. Inline comment around the included bug fix

Looking good. Thank you.

Signed-off-by: Yordan Tsintsov <yordan.tsintsov@redis.com>
@onobc onobc removed the status: waiting-for-triage An issue we've not yet triaged label Feb 6, 2026
@onobc onobc added this to the 4.1 M1 (2026.0.0) milestone Feb 6, 2026
@onobc onobc closed this in 6f9eb82 Feb 6, 2026
onobc added a commit that referenced this pull request Feb 6, 2026
Removes redundant `expiration` from Javadocs.

Original Pull Request #3305
@onobc onobc added the type: enhancement A general enhancement label Feb 6, 2026
@onobc
Copy link
Contributor

onobc commented Feb 6, 2026

Thank for another excellent contribution @Dgramada !

@Dgramada Dgramada deleted the topic/replace-set-command-timeunit-api-with-expiration branch February 9, 2026 08:59
tishun pushed a commit to tishun/spring-data-redis that referenced this pull request Feb 18, 2026
Introduces new methods accepting Expiration (instead of Duration/TimeUnit)
for set, setGet, setIfAbsent, and setIfPresent operations across
ValueOperations, BoundValueOperations, and ReactiveValueOperations.

Deprecates existing TimeUnit-based methods in favor of the new
Expiration-based variants.

Fixes LettuceReactiveStringCommands.setGet() to properly apply expiration
and set options which were previously being ignored.

Adds Kotlin coroutine extension functions for reactive Expiration variants.

Refactors default interface implementation of Duration set methods to
call Expiration set method instead of TimeUnit set method.

Closes spring-projects#3305

Signed-off-by: Yordan Tsintsov <yordan.tsintsov@redis.com>

Signed-off-by: Tihomir Mateev <tihomir.mateev@redis.com>
tishun pushed a commit to tishun/spring-data-redis that referenced this pull request Feb 18, 2026
Removes redundant `expiration` from Javadocs.

Original Pull Request spring-projects#3305

Signed-off-by: Tihomir Mateev <tihomir.mateev@redis.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: enhancement A general enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants