Skip to content

Commit

Permalink
Return command response from synchronous dispatch of transaction cont…
Browse files Browse the repository at this point in the history
…rol commands #1335

Original pull request: #1336.
  • Loading branch information
tzxyz authored and mp911de committed Jul 9, 2020
1 parent 0f82b72 commit 48291d8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/main/java/io/lettuce/core/FutureSyncInvocationHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
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,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);
}

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

Expand Down

0 comments on commit 48291d8

Please sign in to comment.