Merge pull request #626 from HeartSaVioR/fix-pipeline-throws-npe-without-multi
Fix Pipeline throws NPE using exec without multi (fixes #623)
This commit is contained in:
@@ -104,12 +104,18 @@ public class Pipeline extends MultiKeyPipelineBase {
|
||||
}
|
||||
|
||||
public Response<String> discard() {
|
||||
if (currentMulti == null)
|
||||
throw new JedisDataException("DISCARD without MULTI");
|
||||
|
||||
client.discard();
|
||||
currentMulti = null;
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<List<Object>> exec() {
|
||||
if (currentMulti == null)
|
||||
throw new JedisDataException("EXEC without MULTI");
|
||||
|
||||
client.exec();
|
||||
Response<List<Object>> response = super.getResponse(currentMulti);
|
||||
currentMulti.setResponseDependency(response);
|
||||
@@ -118,6 +124,9 @@ public class Pipeline extends MultiKeyPipelineBase {
|
||||
}
|
||||
|
||||
public Response<String> multi() {
|
||||
if (currentMulti != null)
|
||||
throw new JedisDataException("MULTI calls can not be nested");
|
||||
|
||||
client.multi();
|
||||
Response<String> response = getResponse(BuilderFactory.STRING); // Expecting
|
||||
// OK
|
||||
|
||||
@@ -272,6 +272,26 @@ public class PipeliningTest extends Assert {
|
||||
assertEquals("world", r3.get());
|
||||
}
|
||||
|
||||
@Test(expected = JedisDataException.class)
|
||||
public void pipelineExecShoudThrowJedisDataExceptionWhenNotInMulti() {
|
||||
Pipeline pipeline = jedis.pipelined();
|
||||
pipeline.exec();
|
||||
}
|
||||
|
||||
@Test(expected = JedisDataException.class)
|
||||
public void pipelineDiscardShoudThrowJedisDataExceptionWhenNotInMulti() {
|
||||
Pipeline pipeline = jedis.pipelined();
|
||||
pipeline.discard();
|
||||
}
|
||||
|
||||
@Test(expected = JedisDataException.class)
|
||||
public void pipelineMultiShoudThrowJedisDataExceptionWhenAlreadyInMulti() {
|
||||
Pipeline pipeline = jedis.pipelined();
|
||||
pipeline.multi();
|
||||
pipeline.set("foo", "3");
|
||||
pipeline.multi();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDiscardInPipeline() {
|
||||
Pipeline pipeline = jedis.pipelined();
|
||||
|
||||
Reference in New Issue
Block a user