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);
}
这个自己意会吧,就是不能读一个数据读太久

你可能感兴趣的:(redis)