Search code examples
javaspringspring-bootredisredisson

How to clear Redis cache using Redission when Redis deployed to 2 or more containers?


In my Spring Boot project, I have one redis container deployed in Docker swarm cluster. I use it as Hibernate 2nd level cache for the application. I use Redisson client to manually clear the cache using the following code

Config config = new Config();
config.useSingleServer().setAddress("redis://" + redisProperties.getHost() + ":" + redisProperties.getPort());
RedissonClient redisson = Redisson.create(config);
redisson.getKeys().flushdb();
redisson.shutdown();

Now I want to scale it to multiple containers to load balance the requests. If I do that, how can I clear the cache in 2 or more containers at the same time?


Solution

  • Based on response from Redisson author, clearing cache in one container, clears it in all containers