When connecting to a remote Redis with Jedis today, throw the connection Timeout exception: Connect timed out. The specific information is as follows:
Exception in thread "main" redis.clients.jedis.exceptions.JedisConnectionException:java.net.SocketTimeoutException : Connect timed out in Redis.clients.jedis.Connection.connect (connection.java:142) at Redis.clients.jedis.BinaryClient.connect (binaryclient.java:75) at Redis.clients.jedis.Connection.sendCommand ( connection.java:83) at Redis.clients.jedis.BinaryClient.set (binaryclient.java:92) at Redis.clients.jedis.Client.set (client.java:23) at Redis.clients.jedis.Jedis.set (jedis.java:53) at Com.ado.test.redis.RedisTest.main (redistest.java:10) caused by:java.net.SocketTimeoutException:connect timed out at Java.net.PlainSocketImpl.socketConnect (Native method) at Java.net.PlainSocketImpl.doConnect (Plainsocketimpl.java : 351) at Java.net.PlainSocketImpl.connectToAddress (plainsocketimpl.java:213) at Java.net.PlainSocketImpl.connect ( plainsocketimpl.java:200) at Java.net.SocksSocketImpl.connect (sockssocketimpl.java:366) at Java.net.Socket.connect (socket.java:529) at REDIS.CLIENTS.JEdis. Connection.connect (connection.java:137) ... 6 more
After confirmation, there are several possible exclusions:
1, server address configuration error. (confirmed, configured correctly.) )
2, the number of Redis connection is too high. (confirmed, there are no connections on the Redis server.) )
View Jedis connection source, also did not find anything unusual, so suspected is Redis host problem. Using the Telnet command for testing, the discovery is not connected. So the suspect is Redis server firewall is not shut down.
To view server firewall status:
Service Iptables Status
To turn off the firewall:
Service Iptables Stop
Then the connection was made, and this time the connection was successful. Solve the problem.