Skip to content

Could data created by @Indexed automatically expired by @TimeToLive? #3001

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
dzy5639313 opened this issue Sep 20, 2024 · 5 comments
Closed
Labels
for: stackoverflow A question that's better suited to stackoverflow.com

Comments

@dzy5639313
Copy link

When data in redis expired by @timetolive, the secondary index data created by @indexed never expired.
Is it possible to set expire time of secondary index data with the same value as @timetolive

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

mp911de commented Sep 20, 2024

The indexes you refer to were created by Redis Repositories. Redis only supports top-level key TTLs (and since Redis 7.4 also Hash-field TTL). Any entries within a secondary index (set, geoset) cannot be expired by Redis itself.

To address this shortcoming, Spring Data Redis uses Pub/Sub listeners for keyspace events to remove expired elements from secondary indexes. That also means, if your application isn't running or has been disconnected from Redis, the secondary index cleanup isn't performed.

@mp911de mp911de closed this as not planned Won't fix, can't repro, duplicate, stale Sep 20, 2024
@mp911de mp911de added for: stackoverflow A question that's better suited to stackoverflow.com and removed status: waiting-for-triage An issue we've not yet triaged labels Sep 20, 2024
@dzy5639313
Copy link
Author

The indexes you refer to were created by Redis Repositories. Redis only supports top-level key TTLs (and since Redis 7.4 also Hash-field TTL). Any entries within a secondary index (set, geoset) cannot be expired by Redis itself.

To address this shortcoming, Spring Data Redis uses Pub/Sub listeners for keyspace events to remove expired elements from secondary indexes. That also means, if your application isn't running or has been disconnected from Redis, the secondary index cleanup isn't performed.

Does that mean that if I want to delete secondary index data, I need to implement the specific keyspace expire event listener myself?

@mp911de
Copy link
Member

mp911de commented Sep 23, 2024

No, configuring your application with @EnableRedisRepositories(enableKeyspaceEvents = ON_STARTUP) is sufficient.

@dzy5639313
Copy link
Author

No, configuring your application with @EnableRedisRepositories(enableKeyspaceEvents = ON_STARTUP) is sufficient.

thanks!

@nandorholozsnyak
Copy link

Sorry for bothering, the fact that enabling the keyspace event listener will do its job, but it won't work on GCP MemoryStore as the CONFIG command is forbidden.
Is there any other solution for that? I guess it will be an issue to handle that and make sure the event listener starts in this case as well if there is any error during reading the config parameter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: stackoverflow A question that's better suited to stackoverflow.com
Projects
None yet
Development

No branches or pull requests

4 participants