-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 support for GETEX in Spring Redis Cache #2351
Comments
@bytestreme - Before discussing and reviewing any changes to Spring Data Redis, I want to clarify a few things. Your (implied) recommendation is to support cache entry, idle-timeout expiration (TTI) using the Redis GETEX command (as evident in your PR) in addition to cache entry, time-to-live expiration (TTL) currently used by Spring Data Redis's implementation (Javadoc) of Spring Framework's Cache Abstraction.
Second, I also read the DZone article you shared and a few things stood out to me:
As it turns out, local, client-side caching is not a trivial problem. 1 of the most challenging tasks, especially in a distributed topology, is consistency, and not just between server nodes in a cluster (e.g. using replication for HA), but also consistency between client(s) and server(s). Redis makes no guarantees of consistency on the server-side primarily because replica updates are asynchronous. This problem is further compounded by client-side caching, and is typically only used when data updates are infrequent (i.e. reads far exceed writes) or strong consistency is not a major concern. Therefore, it is not surprising that these features are only available in the PRO version, or rather commercial/paid option. See the comparisons between the OSS and PRO versions, here. Next up, "cache entry, idle-timeout expiration (TTI)"... |
Regarding your specific (implied) ask for cache entry, idle-timeout expiration (TTI), Redis's GETEX command is NOT an implementation of TTI. Rather, it is a per cache entry (key-based) time-to-live expiration (TTL) policy on By way of example, if you were to execute these series of commands: $ SET sessionId 123
$ GETEX sessionId EX 600 // Session timeout after 5 minutes
"123"
// Wait 4 minutes
$ GET sessionId
"123"
// Wait 1 minute
$ GET sessionId
(nil) That is, the simple act of "reading" the key (e.g. "sessionId") does NOT reset the expiration timeout (back to 5 minutes) upon (read) access. Although, if each subsequent If another application is not using caching, but accessing the same data for some other purpose while the data is loaded and actively being used, then this will not reset the expiration timeout. Additionally, even if another application uses caching, but applies different configuration, then it is possible the object will still expire even when being accessed. All of this is to say that data policies like expiration are best left to the underlying data store (as suggested/recommended), especially in a distributed topology arrangement, so that such policies are uniformly applied across the system and consistently exhibit the desired behavior in application. Otherwise, this becomes quite challenging to debug when unexpected situations arise (e.g. users being unexpectedly logged out in the middle of their session). |
There is another Redis command OBJECT IDLETIME that properly assesses whether a particular key is "idle". By way of example: 127.0.0.1:6379> GET sessionId
(nil)
127.0.0.1:6379> SET sessionId ABC
OK
127.0.0.1:6379> GET sessionId
"ABC"
127.0.0.1:6379> OBJECT IDLETIME sessionId
(integer) 30
127.0.0.1:6379> GETEX sessionId EX 30
"ABC"
127.0.0.1:6379> OBJECT IDLETIME sessionId
(integer) 17
127.0.0.1:6379> GET sessionId
"ABC"
127.0.0.1:6379> OBJECT IDLETIME sessionId
(integer) 2
127.0.0.1:6379> GET sessionId
(nil)
127.0.0.1:6379> OBJECT IDLETIME sessionId
(nil) I performed these commands within a span of only a few seconds apart. Still, the object (ABC) with key (sessionId) expired after 30 seconds (set with Therefore, without some "external" TTI expiration monitor (perhaps using To be clear, an TTI expiration monitor really belongs in the underlying data store, and is not something that we are interested in adding to and maintaining in Spring Data Redis, even if other frameworks like Redisson support such features to some extent, which is limited by unenforceable, consistent application thereof. |
We now support time-to-idle (TTI) expiration policies in Spring Data Redis's Cache implementation for cache reads. This TTI behavior is achieved with the use of the Redis GETEX command an consistently using the same TTL configuration for all cache operations when TTI is enabled. Closes spring-projects#2351 Original pull request: spring-projects#2643
We now support time-to-idle (TTI) expiration policies for cache reads. The TTI implementation is achieved with the use of the Redis GETEX command on Cache.get(key) operations as well as consistently using the same TTL configuration for all cache operations when TTI is enabled and TTL expiration has been configured, with the use of a TtlFunction or fixed Duration. Closes spring-projects#2351 Original pull request: spring-projects#2643
We now support time-to-idle (TTI) expiration policies for cache reads. The TTI implementation is achieved with the use of the Redis GETEX command on Cache.get(key) operations as well as consistently using the same TTL configuration for all cache operations when TTI is enabled and TTL expiration has been configured, with the use of a TtlFunction or fixed Duration. Closes spring-projects#2351 Original pull request: spring-projects#2643
See PR #2649. |
… is available. The Redis GETEX command is only available when the Redis server version is at least 6.2.0. Closes spring-projects#2351
…Spring Data Redis Cache implementation. Edit Javadoc in RedisCacheManager. Closes spring-projects#2351
Hi,
in version > 2.6:
https://docs.spring.io/spring-data/data-redis/docs/current/reference/html/#new-in-2.6.0
you support GETEX command that permits (I think) to have a kind of "time to idle" like in EhCache (
ExpiryPolicyBuilder.timeToIdleExpiration
) where the key doesn't expire if someone get its value.I updated my
pom.xml
with:but in
RedisCacheConfiguration
class there is onlyDuration ttl
attribute.I found this https://dzone.com/articles/how-to-boost-redis-with-local-caching-in-java but it talks about Redisson and I found in library that is possible to have timeToLive and Idle:
Do I miss something?
Thanks
The text was updated successfully, but these errors were encountered: