diff --git a/gradle.properties b/gradle.properties index f09fb8eb53..6d66de3d88 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ jredisVersion=06052013 jedisVersion=2.4.1 springVersion=3.2.8.RELEASE log4jVersion=1.2.17 -version=1.3.0.BUILD-SNAPSHOT +version=1.3.0.DATAREDIS-226-SNAPSHOT srpVersion=0.7 jacksonVersion=1.8.8 fasterXmlJacksonVersion=2.2.0 diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnection.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnection.java index 046b5cff28..9fb72fe7a5 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnection.java @@ -49,6 +49,7 @@ import org.springframework.data.redis.connection.Subscription; import org.springframework.data.redis.connection.convert.Converters; import org.springframework.data.redis.connection.convert.TransactionResultConverter; +import org.springframework.data.redis.core.RedisCommand; import org.springframework.data.redis.core.types.RedisClientInfo; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -294,18 +295,22 @@ public Object execute(String command, CommandOutput commandOutputTypeHint, byte[ try { String name = command.trim().toUpperCase(); CommandType cmd = CommandType.valueOf(name); - CommandArgs cmdArg = new CommandArgs(CODEC); + validateCommandIfRunningInTransactionMode(cmd, args); + + CommandArgs cmdArg = new CommandArgs(CODEC); if (!ObjectUtils.isEmpty(args)) { cmdArg.addKeys(args); } CommandOutput expectedOutput = commandOutputTypeHint != null ? commandOutputTypeHint : typeHints.getTypeHint(cmd); if (isPipelined()) { + pipeline(new LettuceResult(getAsyncConnection().dispatch(cmd, expectedOutput, cmdArg))); return null; } else if (isQueueing()) { - transaction(new LettuceResult(getAsyncConnection().dispatch(cmd, expectedOutput, cmdArg))); + + transaction(new LettuceTxResult(getAsyncConnection().dispatch(cmd, expectedOutput, cmdArg))); return null; } else { return await(getAsyncConnection().dispatch(cmd, expectedOutput, cmdArg)); @@ -3168,6 +3173,25 @@ private ZStoreArgs zStoreArgs(Aggregate aggregate, int[] weights) { return args; } + private void validateCommandIfRunningInTransactionMode(CommandType cmd, byte[]... args) { + + if (this.isQueueing()) { + validateCommand(cmd, args); + } + } + + private void validateCommand(CommandType cmd, byte[]... args) { + + RedisCommand redisCommand = RedisCommand.failsafeCommandLookup(cmd.name()); + if (!RedisCommand.UNKNOWN.equals(redisCommand) && redisCommand.requiresArguments()) { + try { + redisCommand.validateArgumentCount(args != null ? args.length : 0); + } catch (IllegalArgumentException e) { + throw new InvalidDataAccessApiUsageException(String.format("Validation failed for %s command.", cmd), e); + } + } + } + /** * {@link TypeHints} provide {@link CommandOutput} information for a given {@link CommandType}. * diff --git a/src/main/java/org/springframework/data/redis/core/RedisCommand.java b/src/main/java/org/springframework/data/redis/core/RedisCommand.java index be629b33ea..4115bc8c54 100644 --- a/src/main/java/org/springframework/data/redis/core/RedisCommand.java +++ b/src/main/java/org/springframework/data/redis/core/RedisCommand.java @@ -32,7 +32,7 @@ * @see Redis command list: * https://github.com/antirez/redis/blob/93e7a130fc9594e41ccfc996b5eca7626ae5356a/src/redis.c#L119 */ -enum RedisCommand { +public enum RedisCommand { // -- A APPEND("rw", 2, 2), // AUTH("rw", 1, 1), // diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionTransactionIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionTransactionIntegrationTests.java index 56b460f69c..e269d60065 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionTransactionIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionTransactionIntegrationTests.java @@ -19,7 +19,6 @@ import java.util.Arrays; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.data.redis.connection.AbstractConnectionTransactionIntegrationTests; @@ -40,10 +39,6 @@ @ContextConfiguration("LettuceConnectionIntegrationTests-context.xml") public class LettuceConnectionTransactionIntegrationTests extends AbstractConnectionTransactionIntegrationTests { - @Test - @Ignore("DATAREDIS-226 Exceptions on native execute are swallowed in tx") - public void exceptionExecuteNative() throws Exception {} - @Test(expected = UnsupportedOperationException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testSRandMemberCountNegative() {