How to configure Spring Boot with Redis to prevent data loss on connection failure?
I'm refactoring my project and I've hit a wall trying to I'm working on a personal project and I'm using Spring Boot 2.5.4 with Redis as a caching layer, and I'm working with a critical scenario where my application loses cache data when there's a connection failure to the Redis server... I've configured the Redis connection using the following properties in my `application.properties`: ```properties spring.cache.type=redis spring.redis.host=localhost spring.redis.port=6379 spring.redis.timeout=2000 ``` During testing, if I stop the Redis server while my application is running, I can see the following stack trace in the logs when trying to access the cached data: ``` org.springframework.data.redis.RedisConnectionException: want to get a redis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: connect timed out ``` I want to ensure that my application can handle the connection failure gracefully and that I can implement a retry mechanism to prevent data loss. I've tried using `@Cacheable` annotations on my methods, but once Redis is down, I need to retrieve any cached data anymore, leading to increased load and longer response times. I also experimented with the `Lettuce` Redis client instead of `Jedis`, but I still face disconnections that are not handled well. My goal is to maintain a seamless user experience even in the event of Redis downtime. Hereβs my current configuration for the Redis connection: ```java @Bean public RedisConnectionFactory redisConnectionFactory() { RedisStandaloneConfiguration config = new RedisStandaloneConfiguration("localhost", 6379); return new JedisConnectionFactory(config); } ``` How can I modify this setup to improve fault tolerance and prevent data loss during Redis connection failures? For context: I'm using Java on Windows. How would you solve this? The stack includes Java and several other technologies. The stack includes Java and several other technologies. My team is using Java for this CLI tool. I appreciate any insights!