標籤:java jedis redis
今天在用jedis串連遠端redis時,拋出連線逾時異常:connect timed out。具體資訊如下:
Exception in thread "main" redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: connect timed outat 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 outat 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
經過確認,排除了幾種可能:
1、伺服器位址配置錯誤。(經確認,配置無誤。)
2、redis串連數量過多。(經確認,沒有任何串連在redis伺服器上。)
查看jedis串連源碼,也沒發現有什麼異常,於是懷疑是redis主機的問題。使用telnet命令進行測試,發現也是串連不上。於是懷疑是redis伺服器防火牆沒關閉。
查看伺服器防火牆狀態:
services iptables status
關閉防火牆:
services iptables stop
然後再進行串連,這次就很快串連成功了。問題解決。
redis遠端連線逾時