Skip to content

Commit

Permalink
Allow completion of multiple subsequent MULTI calls #673
Browse files Browse the repository at this point in the history
  • Loading branch information
mp911de committed Jan 23, 2018
1 parent 2e59f1e commit c893778
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2011-2017 the original author or authors.
* Copyright 2011-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -73,6 +73,6 @@ private static boolean isTransactionActive(StatefulConnection<?, ?> connection)
}

private static boolean isNonTxControlMethod(String methodName) {
return !methodName.equals("exec") && !methodName.equals("multi");
return !methodName.equals("exec") && !methodName.equals("multi") && !methodName.equals("discard");
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2011-2017 the original author or authors.
* Copyright 2011-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -210,7 +210,7 @@ public <T, C extends RedisCommand<K, V, T>> C dispatch(C command) {
local.setOutput((MultiOutput) multiOutput);
}

if (multi != null) {
if (multi != null && !local.getType().name().equals(MULTI.name())) {
local = new TransactionalCommand<>(local);
multi.add(local);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2011-2017 the original author or authors.
* Copyright 2011-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -33,6 +33,7 @@
* @author Mark Paluch
*/
public class TransactionCommandTest extends AbstractRedisClientTest {

@Rule
public ExpectedException exception = ExpectedException.none();

Expand Down Expand Up @@ -109,4 +110,12 @@ public void execWithoutMulti() {
redis.exec();
}

@Test
public void multiCalledTwiceShouldFail() {
exception.expect(RedisCommandExecutionException.class);
exception.expectMessage("ERR MULTI calls can not be nested");

redis.multi();
redis.multi();
}
}

0 comments on commit c893778

Please sign in to comment.