Configure Jedis timeout

If what you want to do is set Jedis connection timeout, you should do it using the special constructor made for that:

public Jedis(final String host, final int port, final int timeout)

What you are doing is setting the timeout on Redis settings from Jedis. Doing CONFIG SET timeout 60, means that Redis will close idle client connections after 60 seconds. That's why you get the exception in Jedis.


This is a bit of an extension to xetorthio's answer, but here is similar approach for use with a JedisPool. (Caveat: this is based on my understanding from looking at the Jedis version 2.6.2 code directly and has not been tested in a live use case.)

    JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
    jedisPoolConfig.setMaxWaitMillis(writeTimeout);
    JedisPool pool = new JedisPool(jedisPoolConfig, redisHost, port, readTimeout);

The writeTimeout is max time for a Jedis resource from the pool to wait for a write operation.

The readTimeout specified for the pool constructor is the wait time for a socket read, see java.net.Socket.setSoTimeout for more specific details.

Tags:

Java

Redis

Jedis