From 6ea1959cc5308389f5db6d430c3fc8aa122bd32f Mon Sep 17 00:00:00 2001 From: nilskp Date: Fri, 3 Oct 2014 15:36:09 -0500 Subject: [PATCH 1/2] Fixes xetorthio/jedis#758 --- .../java/redis/clients/jedis/Pipeline.java | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/main/java/redis/clients/jedis/Pipeline.java b/src/main/java/redis/clients/jedis/Pipeline.java index c79c969..c3caefc 100644 --- a/src/main/java/redis/clients/jedis/Pipeline.java +++ b/src/main/java/redis/clients/jedis/Pipeline.java @@ -88,17 +88,18 @@ public class Pipeline extends MultiKeyPipelineBase { } /** - * Syncronize pipeline by reading all responses. This operation close the + * Synchronize pipeline by reading all responses. This operation close the * pipeline. In order to get return values from pipelined commands, capture * the different Response of the commands you execute. */ public void sync() { - List unformatted = client.getMany(getPipelinedResponseLength()); - for (Object o : unformatted) { - generateResponse(o); - } + if (client.isConnected()) { + List unformatted = client.getMany(getPipelinedResponseLength()); + for (Object o : unformatted) { + generateResponse(o); + } + } } - /** * Syncronize pipeline by reading all responses. This operation close the * pipeline. Whenever possible try to avoid using this version and use @@ -108,17 +109,21 @@ public class Pipeline extends MultiKeyPipelineBase { * @return A list of all the responses in the order you executed them. */ public List syncAndReturnAll() { - List unformatted = client.getMany(getPipelinedResponseLength()); - List formatted = new ArrayList(); + if (client.isConnected()) { + List unformatted = client.getMany(getPipelinedResponseLength()); + List formatted = new ArrayList(); - for (Object o : unformatted) { - try { - formatted.add(generateResponse(o).get()); - } catch (JedisDataException e) { - formatted.add(e); - } - } - return formatted; + for (Object o : unformatted) { + try { + formatted.add(generateResponse(o).get()); + } catch (JedisDataException e) { + formatted.add(e); + } + } + return formatted; + } else { + return java.util.Collections.emptyList(); + } } public Response discard() { From 745f1b1e4e180460d83423e83e46583103f1ad34 Mon Sep 17 00:00:00 2001 From: nilskp Date: Sat, 4 Oct 2014 11:22:45 -0500 Subject: [PATCH 2/2] Updated fix to xetorthio/jedis#758 --- src/main/java/redis/clients/jedis/Pipeline.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/java/redis/clients/jedis/Pipeline.java b/src/main/java/redis/clients/jedis/Pipeline.java index c3caefc..5dc3179 100644 --- a/src/main/java/redis/clients/jedis/Pipeline.java +++ b/src/main/java/redis/clients/jedis/Pipeline.java @@ -93,15 +93,15 @@ public class Pipeline extends MultiKeyPipelineBase { * the different Response of the commands you execute. */ public void sync() { - if (client.isConnected()) { + if (getPipelinedResponseLength() > 0) { List unformatted = client.getMany(getPipelinedResponseLength()); for (Object o : unformatted) { generateResponse(o); } - } + } } /** - * Syncronize pipeline by reading all responses. This operation close the + * Synchronize pipeline by reading all responses. This operation close the * pipeline. Whenever possible try to avoid using this version and use * Pipeline.sync() as it won't go through all the responses and generate the * right response type (usually it is a waste of time). @@ -109,10 +109,9 @@ public class Pipeline extends MultiKeyPipelineBase { * @return A list of all the responses in the order you executed them. */ public List syncAndReturnAll() { - if (client.isConnected()) { + if (getPipelinedResponseLength() > 0) { List unformatted = client.getMany(getPipelinedResponseLength()); List formatted = new ArrayList(); - for (Object o : unformatted) { try { formatted.add(generateResponse(o).get());