Merge branch 'fixes-758' of github.com:HeartSaVioR/jedis into HeartSaVioR-fixes-758
This commit is contained in:
@@ -88,19 +88,20 @@ 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<Object> unformatted = client.getMany(getPipelinedResponseLength());
|
||||
for (Object o : unformatted) {
|
||||
generateResponse(o);
|
||||
}
|
||||
if (getPipelinedResponseLength() > 0) {
|
||||
List<Object> 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).
|
||||
@@ -108,17 +109,20 @@ public class Pipeline extends MultiKeyPipelineBase {
|
||||
* @return A list of all the responses in the order you executed them.
|
||||
*/
|
||||
public List<Object> syncAndReturnAll() {
|
||||
List<Object> unformatted = client.getMany(getPipelinedResponseLength());
|
||||
List<Object> formatted = new ArrayList<Object>();
|
||||
|
||||
for (Object o : unformatted) {
|
||||
try {
|
||||
formatted.add(generateResponse(o).get());
|
||||
} catch (JedisDataException e) {
|
||||
formatted.add(e);
|
||||
}
|
||||
}
|
||||
return formatted;
|
||||
if (getPipelinedResponseLength() > 0) {
|
||||
List<Object> unformatted = client.getMany(getPipelinedResponseLength());
|
||||
List<Object> formatted = new ArrayList<Object>();
|
||||
for (Object o : unformatted) {
|
||||
try {
|
||||
formatted.add(generateResponse(o).get());
|
||||
} catch (JedisDataException e) {
|
||||
formatted.add(e);
|
||||
}
|
||||
}
|
||||
return formatted;
|
||||
} else {
|
||||
return java.util.Collections.<Object>emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
public Response<String> discard() {
|
||||
|
||||
@@ -450,6 +450,25 @@ public class PipeliningTest extends Assert {
|
||||
|
||||
assertTrue(result.get(3) instanceof JedisDataException);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSyncWithNoCommandQueued() {
|
||||
// we need to test with fresh instance of Jedis
|
||||
Jedis jedis2 = new Jedis(hnp.getHost(), hnp.getPort(), 500);
|
||||
|
||||
Pipeline pipeline = jedis2.pipelined();
|
||||
pipeline.sync();
|
||||
|
||||
jedis2.close();
|
||||
|
||||
jedis2 = new Jedis(hnp.getHost(), hnp.getPort(), 500);
|
||||
|
||||
pipeline = jedis2.pipelined();
|
||||
List<Object> resp = pipeline.syncAndReturnAll();
|
||||
assertTrue(resp.isEmpty());
|
||||
|
||||
jedis2.close();
|
||||
}
|
||||
|
||||
private void verifyHasBothValues(String firstKey, String secondKey,
|
||||
String value1, String value2) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.ArrayList;
|
||||
@@ -18,6 +19,7 @@ import org.junit.Test;
|
||||
import redis.clients.jedis.HostAndPort;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisShardInfo;
|
||||
import redis.clients.jedis.Pipeline;
|
||||
import redis.clients.jedis.Response;
|
||||
import redis.clients.jedis.ShardedJedis;
|
||||
import redis.clients.jedis.ShardedJedisPipeline;
|
||||
@@ -130,4 +132,32 @@ public class ShardedJedisPipelineTest {
|
||||
p.sync();
|
||||
assertNull(shouldNotExist.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSyncWithNoCommandQueued() {
|
||||
JedisShardInfo shardInfo1 = new JedisShardInfo(redis1.getHost(),
|
||||
redis1.getPort());
|
||||
JedisShardInfo shardInfo2 = new JedisShardInfo(redis2.getHost(),
|
||||
redis2.getPort());
|
||||
shardInfo1.setPassword("foobared");
|
||||
shardInfo2.setPassword("foobared");
|
||||
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
|
||||
shards.add(shardInfo1);
|
||||
shards.add(shardInfo2);
|
||||
|
||||
ShardedJedis jedis2 = new ShardedJedis(shards);
|
||||
|
||||
ShardedJedisPipeline pipeline = jedis2.pipelined();
|
||||
pipeline.sync();
|
||||
|
||||
jedis2.close();
|
||||
|
||||
jedis2 = new ShardedJedis(shards);
|
||||
pipeline = jedis2.pipelined();
|
||||
List<Object> resp = pipeline.syncAndReturnAll();
|
||||
assertTrue(resp.isEmpty());
|
||||
|
||||
jedis2.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user