javaredisredisson

Redisson Cache Map does not evict if process is terminated


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.


Solution

  • 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.