From c893778e64ccb5f75d4450695d0d8912f6c0efac Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Tue, 23 Jan 2018 14:23:52 +0100 Subject: [PATCH] Allow completion of multiple subsequent MULTI calls #673 --- .../redis/FutureSyncInvocationHandler.java | 4 ++-- .../redis/StatefulRedisConnectionImpl.java | 4 ++-- .../redis/commands/TransactionCommandTest.java | 11 ++++++++++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/lambdaworks/redis/FutureSyncInvocationHandler.java b/src/main/java/com/lambdaworks/redis/FutureSyncInvocationHandler.java index 93d9472107..58eacaf686 100644 --- a/src/main/java/com/lambdaworks/redis/FutureSyncInvocationHandler.java +++ b/src/main/java/com/lambdaworks/redis/FutureSyncInvocationHandler.java @@ -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. @@ -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"); } } diff --git a/src/main/java/com/lambdaworks/redis/StatefulRedisConnectionImpl.java b/src/main/java/com/lambdaworks/redis/StatefulRedisConnectionImpl.java index d11aaed434..ea8a6268a2 100644 --- a/src/main/java/com/lambdaworks/redis/StatefulRedisConnectionImpl.java +++ b/src/main/java/com/lambdaworks/redis/StatefulRedisConnectionImpl.java @@ -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. @@ -210,7 +210,7 @@ public > 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); } diff --git a/src/test/java/com/lambdaworks/redis/commands/TransactionCommandTest.java b/src/test/java/com/lambdaworks/redis/commands/TransactionCommandTest.java index d3f85e566a..072c4e8561 100644 --- a/src/test/java/com/lambdaworks/redis/commands/TransactionCommandTest.java +++ b/src/test/java/com/lambdaworks/redis/commands/TransactionCommandTest.java @@ -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. @@ -33,6 +33,7 @@ * @author Mark Paluch */ public class TransactionCommandTest extends AbstractRedisClientTest { + @Rule public ExpectedException exception = ExpectedException.none(); @@ -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(); + } }