Difference between Jedis.disconnect() and Jedis.quit()

4,477 views
Skip to first unread message

Neelesh Korade

unread,
Oct 9, 2013, 7:43:16 AM10/9/13
to redi...@googlegroups.com
Hi All

I am trying to understand difference between Jedis.disconnect() and Jedis.quit(). I have gone through the code but it would still help if someone could help me understand the difference and when the two are intended to be used.

Thank you
Neelesh

Jonathan Leibiusky

unread,
Oct 9, 2013, 8:58:26 AM10/9/13
to redi...@googlegroups.com

Quit is actually a redis command that tell the server to close the connection and makes the client also close the connection.
Disconnect is just a client disconnecting the socket.
You should use, unless for some specific reason, quit, because it is more elegant.
Although I am not aware of real differences between them.

Jonathan

--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+u...@googlegroups.com.
To post to this group, send email to redi...@googlegroups.com.
Visit this group at http://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/groups/opt_out.

Neelesh Korade

unread,
Oct 9, 2013, 9:13:44 AM10/9/13
to redi...@googlegroups.com
Thanks Jonathan. For my Jedis connection objects, I initially used quit but I got this error every time-

redis.clients.jedis.exceptions.JedisConnectionException: It seems like server has closed the connection.
When I changed it to jedis.disconnect(), it worked fine. Would you have any clue?

Thanks
Neelesh

Jonathan Leibiusky

unread,
Oct 9, 2013, 9:36:14 AM10/9/13
to redi...@googlegroups.com

Seems like you were doing a quit, but connection was already gone.
Maybe you left the idle for a long time and then issued a 'quit'?

Neelesh Korade

unread,
Oct 9, 2013, 9:46:48 AM10/9/13
to redi...@googlegroups.com
I checked for that but that doesn't seem to be the case. Actually, I tried to use quit/disconnect in my pub/sub code for the subscriber connection. What I see is that the Jedis.subscribe() method sets the connection timeout to '0' which I believe stands for "never timeout".

public void subscribe(JedisPubSub jedisPubSub, String... channels) {
    checkIsInMulti();
    connect();
    client.setTimeoutInfinite();
    jedisPubSub.proceed(client, channels);
    client.rollbackTimeout();
 }


So ideally, the connection should not timeout even if it is idle. Is this understanding correct or am I amiss somewhere?

My sincere apologies for the back-to-back questions but since I am new to redis, I am struggling with it a bit.

Thank you very much for your time and patience.

Neelesh

Jonathan Leibiusky

unread,
Oct 9, 2013, 9:52:45 AM10/9/13
to redi...@googlegroups.com
There are 2 connection timeout configuration. A client and a server.
Probably is the server (redis) who is closing idle connections. As far as I remember, by default (in old versions of redis) it is 300 seconds. In newer versions of redis they changed it to 0 (never).
Please check in your redis.conf

Neelesh Korade

unread,
Oct 9, 2013, 10:13:06 AM10/9/13
to redi...@googlegroups.com
I checked my redis.conf, and it has the timeout set to 0. Further, called jedis.quit as soon as within 1 second but that still resulted in the same exception. Below are the settings and snippet of my test code for your review and in case you want to try and reproduce.

  • redis.conf
# Close the connection after a client is idle for N seconds (0 to disable)
timeout 0

  • code
public void listen(final String channel, String hostname, int port){
        final Jedis jedis = new Jedis(hostname, port);
        final SentinelNotificationListener sentinelListener = new SentinelNotificationListener();
         new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        jedis.subscribe(sentinelListener, channel);
                    } catch (Exception e) {
                    }
                }
            }).start();
       
       
        //Wait for a while before disconnecting/quitting
        try{
            Thread.sleep(1000L);
        }catch(Exception e){
        }
        sentinelListener.unsubscribe();
        jedis.disconnect(); //works
        //jedis.quit(); //doesn't work, throws JedisConnectionException
    }
 

Also, I noticed that the sentinel.conf does not have any such timeout setting (like redis.conf). So when we run redis in sentinel mode, does it pick the server side timeout value from redis.conf? I start my sentinel instance with the following command-
src/redis-server sentinel.conf --sentinel

Thank you
Neelesh

john...@mig33global.com

unread,
Nov 4, 2013, 2:58:52 AM11/4/13
to redi...@googlegroups.com
 think the jedis pool must used quit instead of disconnect in the destroy object.
Reply all
Reply to author
Forward
0 new messages