We are facing this specific issue using lettuce redis library. We are receiving too many RedisCommandTimeoutException. We have set a timeout of 2 secs in redis-cli and 10 ms in redis slow logs. While nothing gets logged in slowlogs our application keeps getting this timeout.
Code we are using is as follows
Duration timeout =
Duration.ofMillis(applicationProperties.redisTimeOut);
RedisClient client = RedisClient.create(RedisURI.create(applicationProperties.redisUrl));
client.setDefaultTimeout(timeout);
RedisCommands<String, String> commands = client.connect().sync();
We have about 100 threads in our application wgich might be using this shared connection
Exception we receive is as follows
io.lettuce.core.RedisCommandTimeoutException: Command timed out
at io.lettuce.core.LettuceFutures.awaitOrCancel(LettuceFutures.java:114)
at io.lettuce.core.FutureSyncInvocationHandler.handleInvocation(FutureSyncInvocationHandler.java:62)
at io.lettuce.core.internal.AbstractInvocationHandler.invoke(AbstractInvocationHandler.java:80)
at com.sun.proxy.$Proxy11.hmget(Unknown Source)
I had the same error and it was that redis fell suddenly and when doing the query it took a long time and several retries, I found this way, I think there is a better way, but it worked for me
@Bean
public LettuceConnectionFactory redisConnectionFactory() {
RedisStandaloneConfiguration redisConf = new RedisStandaloneConfiguration();
redisConf.setHostName(env.getProperty("spring.redis.host"));
redisConf.setPort(Integer.parseInt(env.getProperty("spring.redis.port")));
redisConf.setPassword(RedisPassword.of(env.getProperty("spring.redis.password")));
LettuceConnectionFactory factory = new LettuceConnectionFactory(redisConf);
factory.setTimeout(500L); //timeout to redis
return factory;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With