How to resolve SocketTimeoutException Read timed out with springboot and redis
1. Introduction
Sometimes, when we use Redis in a Spring Boot application, we encounter the following exception:
INFO | jvm 1 | 2019/07/13 20:09:46 | Caused by: redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: Read timed outINFO | jvm 1 | 2019/07/13 20:09:46 | at redis.clients.util.RedisInputStream.ensureFill(RedisInputStream.java:202) ~[jedis-2.9.0.jar:na]INFO | jvm 1 | 2019/07/13 20:09:46 | at redis.clients.util.RedisInputStream.readByte(RedisInputStream.java:40) ~[jedis-2.9.0.jar:na]INFO | jvm 1 | 2019/07/13 20:09:46 | at redis.clients.jedis.Protocol.process(Protocol.java:151) ~[jedis-2.9.0.jar:na]INFO | jvm 1 | 2019/07/13 20:09:46 | at redis.clients.jedis.Protocol.read(Protocol.java:215) ~[jedis-2.9.0.jar:na]INFO | jvm 1 | 2019/07/13 20:09:46 | at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:340) ~[jedis-2.9.0.jar:na]INFO | jvm 1 | 2019/07/13 20:09:46 | at redis.clients.jedis.Connection.getStatusCodeReply(Connection.java:239) ~[jedis-2.9.0.jar:na]INFO | jvm 1 | 2019/07/13 20:09:46 | at redis.clients.jedis.BinaryJedis.quit(BinaryJedis.java:253) ~[jedis-2.9.0.jar:na]INFO | jvm 1 | 2019/07/13 20:09:46 | at org.springframework.data.redis.connection.jedis.JedisConnection.close(JedisConnection.java:325) ~[spring-data-redis-1.8.9.RELEASE.jar:na]INFO | jvm 1 | 2019/07/13 20:09:46 | ... 7 common frames omittedINFO | jvm 1 | 2019/07/13 20:09:46 | Caused by: java.net.SocketTimeoutException: Read timed outINFO | jvm 1 | 2019/07/13 20:09:46 | at java.net.SocketInputStream.socketRead0(Native Method) ~[na:1.8.0_212]INFO | jvm 1 | 2019/07/13 20:09:46 | at java.net.SocketInputStream.socketRead(SocketInputStream.java:116) ~[na:1.8.0_212]INFO | jvm 1 | 2019/07/13 20:09:46 | at java.net.SocketInputStream.read(SocketInputStream.java:171) ~[na:1.8.0_212]INFO | jvm 1 | 2019/07/13 20:09:46 | at java.net.SocketInputStream.read(SocketInputStream.java:141) ~[na:1.8.0_212]INFO | jvm 1 | 2019/07/13 20:09:46 | at java.net.SocketInputStream.read(SocketInputStream.java:127) ~[na:1.8.0_212]INFO | jvm 1 | 2019/07/13 20:09:46 | at redis.clients.util.RedisInputStream.ensureFill(RedisInputStream.java:196) ~[jedis-2.9.0.jar:na]INFO | jvm 1 | 2019/07/13 20:09:46 | ... 14 common frames omitted
2. Environments
- Spring Boot 1.x and 2.x
3. The Solution
3.1 Increase the Spring Boot Redis Connection Timeout
You can resolve this issue by increasing the Redis connection timeout using the following property:
spring.redis.timeout=30000
This configuration sets the Redis connection timeout to 30 seconds.
4. Summary
In this post, we discussed how to resolve the SocketTimeoutException: Read timed out
error in Spring Boot applications using Redis. By increasing the spring.redis.timeout
property, you can ensure that your application waits longer for a response from the Redis server, reducing the likelihood of timeouts. For a complete list of Spring Boot properties, you can refer to the Spring Boot Common Application Properties documentation.
Final Words + More Resources
My intention with this article was to help others who might be considering solving such a problem. So I hope that’s been the case here. If you still have any questions, don’t hesitate to ask me by email: Email me
Here are also the most important links from this article along with some further resources that will help you in this scope:
Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!