1. 程式人生 > >redis的客戶端jedis裡構造器中有soTimeout和connectionTimeout兩個引數,分別代表什麼

redis的客戶端jedis裡構造器中有soTimeout和connectionTimeout兩個引數,分別代表什麼

connectionTimeout:表示連線超時時間

例如構造器

public Jedis(String host, int port, int timeout) {
    super(host, port, timeout);
}
public static void main(String[] args) {
    Jedis jedis = new Jedis("192.168.3.102",6379,10000);
    System.out.println("測試連線:"+jedis.ping());
}
Exception in thread "main" redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: connect timed out
at redis.clients.jedis.Connection.connect(Connection.java:207)
at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:93)
at redis.clients.jedis.Connection.sendCommand(Connection.java:126)
at redis.clients.jedis.Connection.sendCommand(Connection.java:121)
at redis.clients.jedis.BinaryClient.ping(BinaryClient.java:106)
at redis.clients.jedis.BinaryJedis.ping(BinaryJedis.java:195)
at com.umbrella.common.session.utils.SessionUtil.main(SessionUtil.java:150)
Caused by: java.net.SocketTimeoutException: connect timed out
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at redis.clients.jedis.Connection.connect(Connection.java:184)
... 6 more


Process finished with exit code 1

soTimeout:表示讀取資料超時時間

例如構造器

public Jedis(String host, int port, int connectionTimeout, int soTimeout) {
    super(host, port, connectionTimeout, soTimeout);
}
這個自己意會吧,就是不能讀一個數據讀太久