add checks when server closes idle connections
This commit is contained in:
@@ -16,9 +16,11 @@
|
|||||||
|
|
||||||
package redis.clients.util;
|
package redis.clients.util;
|
||||||
|
|
||||||
import redis.clients.jedis.JedisException;
|
import java.io.FilterInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
import java.io.*;
|
import redis.clients.jedis.JedisException;
|
||||||
|
|
||||||
public class RedisInputStream extends FilterInputStream {
|
public class RedisInputStream extends FilterInputStream {
|
||||||
|
|
||||||
@@ -83,7 +85,12 @@ public class RedisInputStream extends FilterInputStream {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new JedisException(e);
|
throw new JedisException(e);
|
||||||
}
|
}
|
||||||
return sb.toString();
|
String reply = sb.toString();
|
||||||
|
if (reply.isEmpty()) {
|
||||||
|
throw new JedisException(
|
||||||
|
"It seems like server has closed the connection.");
|
||||||
|
}
|
||||||
|
return reply;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import java.util.Map;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import redis.clients.jedis.Jedis;
|
import redis.clients.jedis.Jedis;
|
||||||
|
import redis.clients.jedis.JedisException;
|
||||||
import redis.clients.jedis.JedisShardInfo;
|
import redis.clients.jedis.JedisShardInfo;
|
||||||
import redis.clients.jedis.Protocol;
|
import redis.clients.jedis.Protocol;
|
||||||
import redis.clients.jedis.tests.commands.JedisCommandTestBase;
|
import redis.clients.jedis.tests.commands.JedisCommandTestBase;
|
||||||
@@ -41,4 +42,16 @@ public class JedisTest extends JedisCommandTestBase {
|
|||||||
Jedis jedis = new Jedis(shardInfo);
|
Jedis jedis = new Jedis(shardInfo);
|
||||||
jedis.get("foo");
|
jedis.get("foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(expected = JedisException.class)
|
||||||
|
public void timeoutConnection() throws Exception {
|
||||||
|
jedis = new Jedis("localhost", 6379, 15000);
|
||||||
|
jedis.auth("foobared");
|
||||||
|
jedis.configSet("timeout", "1");
|
||||||
|
// we need to sleep a long time since redis check for idle connections
|
||||||
|
// every 10 seconds or so
|
||||||
|
Thread.sleep(20000);
|
||||||
|
jedis.hmget("foobar", "foo");
|
||||||
|
jedis.configSet("timeout", "300");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user