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
|
* pipeline. In order to get return values from pipelined commands, capture
|
||||||
* the different Response<?> of the commands you execute.
|
* the different Response<?> of the commands you execute.
|
||||||
*/
|
*/
|
||||||
public void sync() {
|
public void sync() {
|
||||||
List<Object> unformatted = client.getMany(getPipelinedResponseLength());
|
if (getPipelinedResponseLength() > 0) {
|
||||||
for (Object o : unformatted) {
|
List<Object> unformatted = client.getMany(getPipelinedResponseLength());
|
||||||
generateResponse(o);
|
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. Whenever possible try to avoid using this version and use
|
||||||
* Pipeline.sync() as it won't go through all the responses and generate the
|
* Pipeline.sync() as it won't go through all the responses and generate the
|
||||||
* right response type (usually it is a waste of time).
|
* 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.
|
* @return A list of all the responses in the order you executed them.
|
||||||
*/
|
*/
|
||||||
public List<Object> syncAndReturnAll() {
|
public List<Object> syncAndReturnAll() {
|
||||||
List<Object> unformatted = client.getMany(getPipelinedResponseLength());
|
if (getPipelinedResponseLength() > 0) {
|
||||||
List<Object> formatted = new ArrayList<Object>();
|
List<Object> unformatted = client.getMany(getPipelinedResponseLength());
|
||||||
|
List<Object> formatted = new ArrayList<Object>();
|
||||||
for (Object o : unformatted) {
|
for (Object o : unformatted) {
|
||||||
try {
|
try {
|
||||||
formatted.add(generateResponse(o).get());
|
formatted.add(generateResponse(o).get());
|
||||||
} catch (JedisDataException e) {
|
} catch (JedisDataException e) {
|
||||||
formatted.add(e);
|
formatted.add(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return formatted;
|
return formatted;
|
||||||
|
} else {
|
||||||
|
return java.util.Collections.<Object>emptyList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Response<String> discard() {
|
public Response<String> discard() {
|
||||||
|
|||||||
@@ -451,6 +451,25 @@ public class PipeliningTest extends Assert {
|
|||||||
assertTrue(result.get(3) instanceof JedisDataException);
|
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,
|
private void verifyHasBothValues(String firstKey, String secondKey,
|
||||||
String value1, String value2) {
|
String value1, String value2) {
|
||||||
assertFalse(firstKey.equals(secondKey));
|
assertFalse(firstKey.equals(secondKey));
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import static org.junit.Assert.assertEquals;
|
|||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -18,6 +19,7 @@ import org.junit.Test;
|
|||||||
import redis.clients.jedis.HostAndPort;
|
import redis.clients.jedis.HostAndPort;
|
||||||
import redis.clients.jedis.Jedis;
|
import redis.clients.jedis.Jedis;
|
||||||
import redis.clients.jedis.JedisShardInfo;
|
import redis.clients.jedis.JedisShardInfo;
|
||||||
|
import redis.clients.jedis.Pipeline;
|
||||||
import redis.clients.jedis.Response;
|
import redis.clients.jedis.Response;
|
||||||
import redis.clients.jedis.ShardedJedis;
|
import redis.clients.jedis.ShardedJedis;
|
||||||
import redis.clients.jedis.ShardedJedisPipeline;
|
import redis.clients.jedis.ShardedJedisPipeline;
|
||||||
@@ -130,4 +132,32 @@ public class ShardedJedisPipelineTest {
|
|||||||
p.sync();
|
p.sync();
|
||||||
assertNull(shouldNotExist.get());
|
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