connect in sendCommand() and don't check with isConnected() two times
This commit is contained in:
committed by
Jonathan Leibiusky
parent
a614f1ff3e
commit
c6507e6187
@@ -50,9 +50,13 @@ public class Connection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected Connection sendCommand(String name, String... args) {
|
protected Connection sendCommand(String name, String... args) {
|
||||||
if (!isConnected()) {
|
try {
|
||||||
throw new JedisException("Please connect Jedis before using it.");
|
connect();
|
||||||
}
|
} catch (UnknownHostException e) {
|
||||||
|
throw new JedisException("Could not connect to redis-server", e);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new JedisException("Could not connect to redis-server", e);
|
||||||
|
}
|
||||||
protocol.sendCommand(outputStream, name, args);
|
protocol.sendCommand(outputStream, name, args);
|
||||||
pipelinedCommands++;
|
pipelinedCommands++;
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
@@ -15,4 +15,8 @@ public class JedisException extends RuntimeException {
|
|||||||
public JedisException(IOException e) {
|
public JedisException(IOException e) {
|
||||||
super(e);
|
super(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public JedisException(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import redis.clients.jedis.Protocol;
|
|||||||
import redis.clients.jedis.tests.commands.JedisCommandTestBase;
|
import redis.clients.jedis.tests.commands.JedisCommandTestBase;
|
||||||
|
|
||||||
public class JedisTest extends JedisCommandTestBase {
|
public class JedisTest extends JedisCommandTestBase {
|
||||||
@Test(expected = JedisException.class)
|
@Test
|
||||||
public void useWithoutConnecting() {
|
public void useWithoutConnecting() {
|
||||||
Jedis jedis = new Jedis("localhost");
|
Jedis jedis = new Jedis("localhost");
|
||||||
jedis.dbSize();
|
jedis.dbSize();
|
||||||
@@ -31,4 +31,4 @@ public class JedisTest extends JedisCommandTestBase {
|
|||||||
assertEquals(hash, jedis.hgetAll("foo"));
|
assertEquals(hash, jedis.hgetAll("foo"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user