Jedis jedis = new Jedis("localhost", 6379, 8); jedis.connect(); Thread.sleep(500); System.out.println(jedis.isConnected()); Thread.sleep(10000); System.out.println(jedis.isConnected()); 

Console output

 true true 

In the redis constructor, the timeout time is specified in seconds, so the idea is that the active connection should not close after 8 seconds but not close what am I doing wrong?

  • can jedis, not redis. I do not know what this class is and what it does. And ps, if these are sockets, then there is no client tracking, so they can be cut off and you will think that they are connected. When writing to the output stream of a socket, it throws an exception saying that the computer rejected you, the connection no longer exists. And isConnect will return true boolean to you there, it doesn’t do neyku checks. - Denis Kotlyarov
  • Even in the documentation you do not send, there in the project "self-documenting code." In general, this is not a timeout of inactivity, but a timeout of blocking operations on a tcp socket (connect, read), in milliseconds. Those. if 8 ms failed to connect, connect() would throw an exception. You seem to need jedis.configSet("timeout", "8"); - zRrr
  • Yes, you are right the second option would jedis.configSet("timeout", "8"); me, but there is one thing but jedis.configSet("timeout", "8"); removes inactive skin connections for 8 seconds but I need to remove not all inactive but only those where the timeout is set. in other words, is it possible to set a timeout for the connection that we are doing at the moment and not to affect other connections? - drugs_and_code

0