diff --git a/.gitignore b/.gitignore index e917613..26f012c 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,6 @@ .gradle/ target/ build/ +/appendonly.aof +/dump.rdb +/nohup.out diff --git a/src/main/java/redis/clients/jedis/Connection.java b/src/main/java/redis/clients/jedis/Connection.java index 9493fb9..876cf51 100644 --- a/src/main/java/redis/clients/jedis/Connection.java +++ b/src/main/java/redis/clients/jedis/Connection.java @@ -61,6 +61,24 @@ public class Connection { } } + protected Object read() { + try { + return protocol.read(inputStream); + } catch (JedisConnectionException e) { + disconnect(); + throw new JedisConnectionException(e); + } + } + + protected void sendProtocolCommand(final Command cmd, final byte[]... args) { + try { + protocol.sendCommand(outputStream, cmd, args); + } catch (JedisConnectionException e) { + disconnect(); + throw new JedisConnectionException(e); + } + } + protected Connection sendCommand(final Command cmd, final String... args) { final byte[][] bargs = new byte[args.length][]; for (int i = 0; i < args.length; i++) { @@ -71,14 +89,14 @@ public class Connection { protected Connection sendCommand(final Command cmd, final byte[]... args) { connect(); - protocol.sendCommand(outputStream, cmd, args); + sendProtocolCommand(cmd, args); pipelinedCommands++; return this; } protected Connection sendCommand(final Command cmd) { connect(); - protocol.sendCommand(outputStream, cmd, new byte[0][]); + sendProtocolCommand(cmd, new byte[0][]); pipelinedCommands++; return this; } @@ -145,7 +163,7 @@ public class Connection { protected String getStatusCodeReply() { flush(); pipelinedCommands--; - final byte[] resp = (byte[]) protocol.read(inputStream); + final byte[] resp = (byte[]) read(); if (null == resp) { return null; } else { @@ -165,13 +183,13 @@ public class Connection { public byte[] getBinaryBulkReply() { flush(); pipelinedCommands--; - return (byte[]) protocol.read(inputStream); + return (byte[]) read(); } public Long getIntegerReply() { flush(); pipelinedCommands--; - return (Long) protocol.read(inputStream); + return (Long) read(); } public List getMultiBulkReply() { @@ -182,14 +200,14 @@ public class Connection { public List getBinaryMultiBulkReply() { flush(); pipelinedCommands--; - return (List) protocol.read(inputStream); + return (List) read(); } @SuppressWarnings("unchecked") public List getObjectMultiBulkReply() { flush(); pipelinedCommands--; - return (List) protocol.read(inputStream); + return (List) read(); } public List getAll() { @@ -200,7 +218,7 @@ public class Connection { List all = new ArrayList(); flush(); while (pipelinedCommands > except) { - all.add(protocol.read(inputStream)); + all.add(read()); pipelinedCommands--; } return all; @@ -209,6 +227,6 @@ public class Connection { public Object getOne() { flush(); pipelinedCommands--; - return protocol.read(inputStream); + return read(); } -} \ No newline at end of file +}