diff --git a/src/main/java/io/lettuce/core/FutureSyncInvocationHandler.java b/src/main/java/io/lettuce/core/FutureSyncInvocationHandler.java index 4847d31c3e..a4c43e1ec5 100644 --- a/src/main/java/io/lettuce/core/FutureSyncInvocationHandler.java +++ b/src/main/java/io/lettuce/core/FutureSyncInvocationHandler.java @@ -23,6 +23,7 @@ import io.lettuce.core.api.StatefulRedisConnection; import io.lettuce.core.internal.AbstractInvocationHandler; import io.lettuce.core.internal.TimeoutProvider; +import io.lettuce.core.protocol.CommandType; import io.lettuce.core.protocol.RedisCommand; /** @@ -63,7 +64,7 @@ protected Object handleInvocation(Object proxy, Method method, Object[] args) th RedisFuture command = (RedisFuture) result; - if (isNonTxControlMethod(method.getName()) && isTransactionActive(connection)) { + if (isNonTxControlMethod(method.getName(), args) && isTransactionActive(connection)) { return null; } @@ -91,8 +92,11 @@ private static boolean isTransactionActive(StatefulConnection connection) return connection instanceof StatefulRedisConnection && ((StatefulRedisConnection) connection).isMulti(); } - private static boolean isNonTxControlMethod(String methodName) { - return !methodName.equals("exec") && !methodName.equals("multi") && !methodName.equals("discard"); + private static boolean isNonTxControlMethod(String methodName, Object[] args) { + return !methodName.equals("exec") && !methodName.equals("multi") && !methodName.equals("discard") && !(methodName + .equals("dispatch") && args.length > 0 && args[0] == CommandType.MULTI) && !(methodName + .equals("dispatch") && args.length > 0 && args[0] == CommandType.EXEC) && !(methodName + .equals("dispatch") && args.length > 0 && args[0] == CommandType.DISCARD); } } diff --git a/src/test/java/io/lettuce/core/commands/CustomCommandIntegrationTests.java b/src/test/java/io/lettuce/core/commands/CustomCommandIntegrationTests.java index 8d92c57661..ae1e8d262e 100644 --- a/src/test/java/io/lettuce/core/commands/CustomCommandIntegrationTests.java +++ b/src/test/java/io/lettuce/core/commands/CustomCommandIntegrationTests.java @@ -96,6 +96,14 @@ void dispatchTransactions() { assertThat(exec).hasSize(1).contains("OK"); } + @Test + void dispatchMulti() { + String response = redis.dispatch(CommandType.MULTI, new StatusOutput<>(StringCodec.UTF8)); + assertThat(response).isEqualTo("OK"); + TransactionResult exec = redis.exec(); + assertThat(exec).isEmpty(); + } + @Test void standaloneAsyncPing() {