|
49 | 49 | import org.springframework.data.redis.connection.Subscription;
|
50 | 50 | import org.springframework.data.redis.connection.convert.Converters;
|
51 | 51 | import org.springframework.data.redis.connection.convert.TransactionResultConverter;
|
| 52 | +import org.springframework.data.redis.core.RedisCommand; |
52 | 53 | import org.springframework.data.redis.core.types.RedisClientInfo;
|
53 | 54 | import org.springframework.util.Assert;
|
54 | 55 | import org.springframework.util.ClassUtils;
|
@@ -294,18 +295,22 @@ public Object execute(String command, CommandOutput commandOutputTypeHint, byte[
|
294 | 295 | try {
|
295 | 296 | String name = command.trim().toUpperCase();
|
296 | 297 | CommandType cmd = CommandType.valueOf(name);
|
297 |
| - CommandArgs<byte[], byte[]> cmdArg = new CommandArgs<byte[], byte[]>(CODEC); |
298 | 298 |
|
| 299 | + validateCommandIfRunningInTransactionMode(cmd, args); |
| 300 | + |
| 301 | + CommandArgs<byte[], byte[]> cmdArg = new CommandArgs<byte[], byte[]>(CODEC); |
299 | 302 | if (!ObjectUtils.isEmpty(args)) {
|
300 | 303 | cmdArg.addKeys(args);
|
301 | 304 | }
|
302 | 305 |
|
303 | 306 | CommandOutput expectedOutput = commandOutputTypeHint != null ? commandOutputTypeHint : typeHints.getTypeHint(cmd);
|
304 | 307 | if (isPipelined()) {
|
| 308 | + |
305 | 309 | pipeline(new LettuceResult(getAsyncConnection().dispatch(cmd, expectedOutput, cmdArg)));
|
306 | 310 | return null;
|
307 | 311 | } else if (isQueueing()) {
|
308 |
| - transaction(new LettuceResult(getAsyncConnection().dispatch(cmd, expectedOutput, cmdArg))); |
| 312 | + |
| 313 | + transaction(new LettuceTxResult(getAsyncConnection().dispatch(cmd, expectedOutput, cmdArg))); |
309 | 314 | return null;
|
310 | 315 | } else {
|
311 | 316 | return await(getAsyncConnection().dispatch(cmd, expectedOutput, cmdArg));
|
@@ -3168,6 +3173,25 @@ private ZStoreArgs zStoreArgs(Aggregate aggregate, int[] weights) {
|
3168 | 3173 | return args;
|
3169 | 3174 | }
|
3170 | 3175 |
|
| 3176 | + private void validateCommandIfRunningInTransactionMode(CommandType cmd, byte[]... args) { |
| 3177 | + |
| 3178 | + if (this.isQueueing()) { |
| 3179 | + validateCommand(cmd, args); |
| 3180 | + } |
| 3181 | + } |
| 3182 | + |
| 3183 | + private void validateCommand(CommandType cmd, byte[]... args) { |
| 3184 | + |
| 3185 | + RedisCommand redisCommand = RedisCommand.failsafeCommandLookup(cmd.name()); |
| 3186 | + if (!RedisCommand.UNKNOWN.equals(redisCommand) && redisCommand.requiresArguments()) { |
| 3187 | + try { |
| 3188 | + redisCommand.validateArgumentCount(args != null ? args.length : 0); |
| 3189 | + } catch (IllegalArgumentException e) { |
| 3190 | + throw new InvalidDataAccessApiUsageException(String.format("Validation failed for %s command.", cmd), e); |
| 3191 | + } |
| 3192 | + } |
| 3193 | + } |
| 3194 | + |
3171 | 3195 | /**
|
3172 | 3196 | * {@link TypeHints} provide {@link CommandOutput} information for a given {@link CommandType}.
|
3173 | 3197 | *
|
|
0 commit comments