Reputation: 53
I am using Redisson's RMapCache to handle some distributed collections in my application.
The keys in these collections, should expire after some time, so when adding keys I set the TTL:
RMapCache<String, MyClass> cacheMap = GetMap("test");
cacheMap.put("DTO1", myClassInstance, 20, TimeUnit.SECONDS);
So after 20 seconds the Key should expire. This works perfectly, if the process is not terminated before the expiration timestamp. However, if for any reason the process dies, then the key is never cleared, which means that the eviction is handled by Redisson within the Java process and not by Redis itself.
Is there any way to make redisson use the Redis' built-in EXPIRE feature? So that the process that inserts in the Map is not responsible for the keys eviction.
I find the current redisson implementation to be extremely fragile.
Upvotes: 5
Views: 2747
Reputation: 1227
Starting with Redis 7.4+, it is possible to use native eviction (done by Redis) instead of scripted eviction (done by Redisson).
In Redis 7.4+, it is possible to set TTL
on individual HASH
entry thanks to HEXPIRE
command.
In Redisson 3.32.0+, it is possible to use RMapCacheNative
instead of RMapCache
. With RMapCacheNative
, cache entries would be evicted even when process with Redisson is terminated.
Upvotes: 0
Reputation: 10793
Once you create the same RMapCache object after crash it starts evictionScheduler which in turn clears expired entries in Redis.
If you want to rely on Redis eviction process only then use RBucket object. Redis doesn't provide map entry expiration by TTL or idleTime.
Upvotes: 3