Skip to content

Commit

Permalink
Fix issue redis#1335
Browse files Browse the repository at this point in the history
  • Loading branch information
tzxyz committed Jul 7, 2020
1 parent 7272fb6 commit 88a0abd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/main/java/io/lettuce/core/FutureSyncInvocationHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import io.lettuce.core.internal.AbstractInvocationHandler;
import io.lettuce.core.internal.Futures;
import io.lettuce.core.internal.TimeoutProvider;
import io.lettuce.core.protocol.CommandType;
import io.lettuce.core.protocol.RedisCommand;

/**
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -91,8 +92,13 @@ 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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,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() {

Expand Down

0 comments on commit 88a0abd

Please sign in to comment.