Read timed out Exception in watch

818 views
Skip to first unread message

Rajitha R

unread,
Sep 13, 2011, 6:11:07 AM9/13/11
to Jedis
Hi All,

I have been using jedis to insert key-value pairs into the db as
follows:

jedis.watch(key);
Long result=jedis.setnx(key, value);
jedis.expire(key,expiry);
Transaction t=jedis.multi();
list=t.exec();
JedisCacheManager.getCacheManager().returnJedis(jedis);

I am getting an exception ( in lines 1 and 2 of above code ) as
follows:

java.lang.ClassCastException
redis.clients.jedis.exceptions.JedisConnectionException:
java.net.SocketTimeoutException: Read timed out
at redis.clients.jedis.Protocol.process(Protocol.java:74)
at redis.clients.jedis.Protocol.read(Protocol.java:122)
at redis.clients.jedis.Connection.getIntegerReply(Connection.java:
178)
at redis.clients.jedis.Jedis.expire(Jedis.java:272)

I have gone through some of the recent posts where it is told to
increase the timeout in conf file. I am assuming this timeout to be
the one in the Jedispool constructor which i have set to 21600.

I am facing this error when i insert very large number of key-value
pairs into the database and not otherwise.

Kindly help.

Thanks,
Rajitha

Ingvar Bogdahn

unread,
Sep 13, 2011, 7:01:40 AM9/13/11
to jedis...@googlegroups.com
Hi,

Unless I'm mistaken, you should be able to set the socket timeout like this:
jedis.getClient().setTimeout(time)
this should be your first thing to try, since this is the real
exception. However, it is strnage, that you get it...

Concerning the Jedis-related timeout: in the post they must have
refered to the redis-server config file, hence this is not the same as
the timeout in JedisPool. The one in JedisPool goes to a normal Jedis,
which is a client (the Client disconnects after a time from the
server). The timeout in the config file probably defines the timeout,
when the server disconnects the client of itself. It's very easy to
edit the config file, but you can also set most of those settings in
the config file from client side, by using
configSet(EXACT_NAME_OF_PARAMETER, value).

in theory, the exception doesn't have a relation with the your code,
but sometimes exceptions don't reflect well the real problem. You
never know, maybe the above connection problem goes away when solving
other problems (maybe there is some delay that causes the socket time
out?) :
You got the transaction wrong, it should be like this:

jedis.watch(key);
Transaction t=jedis.multi();
Response<Long> resultResp=t.setnx(key, value);
t.exec();
jedis.expire(key,expiry);
Long result = resultResp.get();

Curious: what is this (for)?
JedisCacheManager.getCacheManager().returnJedis(jedis);

please consult the wiki for more details on transactions.

best
ingvar


2011/9/13 Rajitha R <rajit...@gmail.com>:

rajitha r

unread,
Sep 14, 2011, 2:31:16 AM9/14/11
to jedis...@googlegroups.com
Yes you are right.The problem was with my code.Increasing the timeout in Jedispool constructor will remove the Read timeout Exception.

The Jedispool constructor with timeout doesnt specify if it the time needs to be specified in seconds or milliseconds.There lied the confusion for me.


--
Regards,

Rajitha.R

Jonathan Leibiusky

unread,
Sep 14, 2011, 8:52:26 AM9/14/11
to jedis...@googlegroups.com
We should probably add some clarification in the javadocs of JedisPool :)
Reply all
Reply to author
Forward
0 new messages