Skip to content

@RedisHash timeToLive is a long, which is not compatible with the use of spring-style / SPeL #2931

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

Closed
alexisgayte opened this issue Jun 27, 2024 · 5 comments
Labels
status: declined A suggestion or change that we don't feel we should currently apply

Comments

@alexisgayte
Copy link

alexisgayte commented Jun 27, 2024

org.springframework.data.redis.core.RedisHash has a field timeToLive typed as long therefor you cannot use SPeL/Spring-style expression.

timeToLive is often a property coming from env properties and therefor pass from parameter.
The current definition of @RedisHash is @RedisHash(value="myIndex", timeToLive=60)

The issue seems to come from a long running issue (compiler issue) here @scheduled
image

However this is annoying because that force user of @RedisHash to define all index/entity globally using RedisMappingContext bean

    @Bean
    public RedisMappingContext keyValueMappingContext() {
        return new RedisMappingContext(new MappingConfiguration(new IndexConfiguration(), new MyKeyspaceConfiguration()));
    }

    public class MyKeyspaceConfiguration extends KeyspaceConfiguration {

        @Override
        protected Iterable<KeyspaceSettings> initialConfiguration() {
            KeyspaceSettings keyspace = new KeyspaceSettings(Index.class, "myindex:Index");
            keyspace.setTimeToLive(MyIndex.getTtlInSeconds().longValue());
            return Collections.singleton(keyspace);
        }
    }

linked to : spring-projects/spring-boot#41256

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 27, 2024
@mp911de
Copy link
Member

mp911de commented Jun 27, 2024

Have you seen that you can annotate individual properties with @TimeToLive? A numeric property within the data model can serve as a customization hook where you pre-initialize the TTL value with a config value.

@mp911de mp911de added the status: waiting-for-feedback We need additional information before we can continue label Jun 27, 2024
@alexisgayte
Copy link
Author

Yes I have seen it,
But for me this option is not an option as I can't change my data model.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Jun 27, 2024
@mp911de
Copy link
Member

mp911de commented Jun 27, 2024

We cannot change @RedisHash(timeToLive) to a String as that would break existing applications. Right now, we provide a number of approaches assuming a good fit for the majority of applications. If your specific case comes with limitations that do not match our assumptions, then using the global TTL approach is the best approach.

@mp911de mp911de closed this as not planned Won't fix, can't repro, duplicate, stale Jun 27, 2024
@mp911de mp911de added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged status: feedback-provided Feedback has been provided labels Jun 27, 2024
@alexisgayte
Copy link
Author

alexisgayte commented Jun 27, 2024

Thanks for your time, responsivity and effort.

I understand what you are saying but, I do think that not been integrated with spring-style is a missed feature for spring-data-redis.

Interestingly, I am surprised that I am the only one raising this issue.

@mp911de
Copy link
Member

mp911de commented Jun 27, 2024

This is a nuanced topic as introducing a String-based annotation attribute won't make the cut. @Scheduled introduced a series of String attribute alternatives that clutter the API. Their format isn't really convenient. We will reconsider this ticket once spring-projects/spring-framework#30396 has been merged so that string-based durations can be expressed in a more readable manner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

No branches or pull requests

3 participants