Quantcast
Channel: Active questions tagged redis+java - Stack Overflow
Viewing all articles
Browse latest Browse all 2203

Spring boot application fails on startup when Redis server is down

$
0
0

This is a snippet of my configuration class

@Configuration@EnableCachingpublic class RedisCacheConfig extends CachingConfigurerSupport {@Beanpublic LettuceConnectionFactory redisConnectionFactory() {    return new LettuceConnectionFactory(new RedisStandaloneConfiguration(),            LettuceClientConfiguration.builder()                    .commandTimeout(Duration.ofMillis(1000))                    .build());}@Beanpublic RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory connectionFactory) {    RedisTemplate<Object, Object> template = new RedisTemplate<>();    template.setConnectionFactory(connectionFactory);    return template;}//Cache manager configurations follow here...

When the local redis server is up the app works flawlessly but when the redis is down the startup fails with the following:

org.springframework.data.redis.RedisConnectionFailureException: Unableto connect to Redis; nested exception isio.lettuce.core.RedisConnectionException: Unable to connect tolocalhost:6379 atorg.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$ExceptionTranslatingConnectionProvider.translateException(LettuceConnectionFactory.java:1689)atorg.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$ExceptionTranslatingConnectionProvider.getConnection(LettuceConnectionFactory.java:1597)at
...
...
...
...
14 common frames omitted Caused by:io.netty.channel.AbstractChannel$AnnotatedConnectException: Connectionrefused: no further information: localhost/127.0.0.1:6379 Caused by:java.net.ConnectException: Connection refused: no further informationat java.base/sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)atjava.base/sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:777)

When the cache server is down I would like the app to go on and just run as if there was no caching used all. Any try/catch solutions that I found in other questions did not do the trick. Any ideas?


Viewing all articles
Browse latest Browse all 2203

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>