Home > OS >  Redisson doesn't set TTL or cache name correctly
Redisson doesn't set TTL or cache name correctly

Time:10-12

I'm creating a Spring application that uses Redis cache via redisson client.

 @Bean
public CacheManager cacheManager(RedissonClient redissonClient) throws IOException {

    Map<String, CacheConfig> config = new HashMap<String,CacheConfig>();
    config.put("employeesCache", new CacheConfig(24*60*1000, 12*60*1000));
    RedissonSpringCacheManager manager= new RedissonSpringCacheManager(redissonClient, config);

    return manager;
}

However when running this application the cache name created in Redis is {employeesCache}:redisson_options instead of just employeesCache.

Also, when I check for the TTL in the Redis CLI it returns (integer) -1 ,meaning it has not been set.

So the RedissonSpringCacheManager is partially functioning, it creates the cache but without any configuration, can you help me fix it.

I'm using the following Maven dependencies

<dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-redis</artifactId>
    </dependency>

    <dependency>
        <groupId>org.redisson</groupId>
        <artifactId>redisson-spring-boot-starter</artifactId>
        <version>3.13.1</version>
    </dependency>

CodePudding user response:

Redisson use a map to save your data, but keys in the map are not support TTL, so Redisson maintain a {employeesCache}:redisson_options to save the configurations, your employeesCache keys is maintained and deleted by redisson, NOT redis

So, your data will be saved in a map called employeesCache, not in {employeesCache}:redisson_options, just leave it alone.

  • Related