Skip to content

Commit 31b6736

Browse files
committed
Consistently accept varargs with Redis Scripting.
Closes #3010
1 parent 7bedd60 commit 31b6736

File tree

4 files changed

+49
-20
lines changed

4 files changed

+49
-20
lines changed

src/main/antora/modules/ROOT/pages/redis/scripting.adoc

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class Example {
3434
RedisScript<Boolean> script;
3535
3636
public boolean checkAndSet(String expectedValue, String newValue) {
37-
return redisOperations.execute(script, singletonList("key"), asList(expectedValue, newValue));
37+
return redisOperations.execute(script, List.of("key"), expectedValue, newValue);
3838
}
3939
}
4040
----
@@ -52,7 +52,7 @@ public class Example {
5252
RedisScript<Boolean> script;
5353
5454
public Flux<Boolean> checkAndSet(String expectedValue, String newValue) {
55-
return redisOperations.execute(script, singletonList("key"), asList(expectedValue, newValue));
55+
return redisOperations.execute(script, List.of("key"), expectedValue, newValue);
5656
}
5757
}
5858
----

src/main/java/org/springframework/data/redis/core/ReactiveRedisOperations.java

+14
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,20 @@ default <T> Flux<T> execute(RedisScript<T> script, List<K> keys) {
429429
return execute(script, keys, Collections.emptyList());
430430
}
431431

432+
/**
433+
* Executes the given {@link RedisScript}
434+
*
435+
* @param script The script to execute. Must not be {@literal null}.
436+
* @param keys keys that need to be passed to the script. Must not be {@literal null}.
437+
* @param args args that need to be passed to the script. Must not be {@literal null}.
438+
* @return result value of the script {@link Flux#empty()} if {@link RedisScript#getResultType()} is {@literal null},
439+
* likely indicating a throw-away status reply (i.e. "OK").
440+
* @since 3.4
441+
*/
442+
default <T> Flux<T> execute(RedisScript<T> script, List<K> keys, Object... args) {
443+
return execute(script, keys, Arrays.asList(args));
444+
}
445+
432446
/**
433447
* Executes the given {@link RedisScript}
434448
*

src/main/java/org/springframework/data/redis/core/script/ReactiveScriptExecutor.java

+21-6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import reactor.core.publisher.Flux;
1919

2020
import java.nio.ByteBuffer;
21+
import java.util.Arrays;
2122
import java.util.Collections;
2223
import java.util.List;
2324

@@ -30,8 +31,8 @@
3031
* <p>
3132
* Streams of methods returning {@code Mono<K>} or {@code Flux<M>} are terminated with
3233
* {@link org.springframework.dao.InvalidDataAccessApiUsageException} when
33-
* {@link org.springframework.data.redis.serializer.RedisElementReader#read(ByteBuffer)} returns {@code null} for a
34-
* particular element as Reactive Streams prohibit the usage of {@code null} values.
34+
* {@link org.springframework.data.redis.serializer.RedisElementReader#read(ByteBuffer)} returns {@literal null} for a
35+
* particular element as Reactive Streams prohibit the usage of {@literal null} values.
3536
*
3637
* @author Mark Paluch
3738
* @author Christoph Strobl
@@ -67,8 +68,22 @@ default <T> Flux<T> execute(RedisScript<T> script, List<K> keys) {
6768
* Executes the given {@link RedisScript}
6869
*
6970
* @param script The script to execute. Must not be {@literal null}.
70-
* @param keys Any keys that need to be passed to the script. Must not be {@literal null}.
71-
* @param args Any args that need to be passed to the script. Can be {@literal empty}.
71+
* @param keys any keys that need to be passed to the script. Must not be {@literal null}.
72+
* @param args any args that need to be passed to the script. Can be {@literal empty}.
73+
* @return The return value of the script or {@link Flux#empty()} if {@link RedisScript#getResultType()} is
74+
* {@literal null}, likely indicating a throw-away status reply (i.e. "OK")
75+
* @since 3.4
76+
*/
77+
default <T> Flux<T> execute(RedisScript<T> script, List<K> keys, Object... args) {
78+
return execute(script, keys, Arrays.asList(args));
79+
}
80+
81+
/**
82+
* Executes the given {@link RedisScript}
83+
*
84+
* @param script The script to execute. Must not be {@literal null}.
85+
* @param keys any keys that need to be passed to the script. Must not be {@literal null}.
86+
* @param args any args that need to be passed to the script. Can be {@literal empty}.
7287
* @return The return value of the script or {@link Flux#empty()} if {@link RedisScript#getResultType()} is
7388
* {@literal null}, likely indicating a throw-away status reply (i.e. "OK")
7489
*/
@@ -79,8 +94,8 @@ default <T> Flux<T> execute(RedisScript<T> script, List<K> keys) {
7994
* arguments and result.
8095
*
8196
* @param script The script to execute. must not be {@literal null}.
82-
* @param keys Any keys that need to be passed to the script
83-
* @param args Any args that need to be passed to the script
97+
* @param keys any keys that need to be passed to the script.
98+
* @param args any args that need to be passed to the script.
8499
* @param argsWriter The {@link RedisElementWriter} to use for serializing args. Must not be {@literal null}.
85100
* @param resultReader The {@link RedisElementReader} to use for serializing the script return value. Must not be
86101
* {@literal null}.

src/main/java/org/springframework/data/redis/core/script/ScriptExecutor.java

+12-12
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,25 @@ public interface ScriptExecutor<K> {
3030
/**
3131
* Executes the given {@link RedisScript}
3232
*
33-
* @param script The script to execute
34-
* @param keys Any keys that need to be passed to the script
35-
* @param args Any args that need to be passed to the script
36-
* @return The return value of the script or null if {@link RedisScript#getResultType()} is null, likely indicating a
37-
* throw-away status reply (i.e. "OK")
33+
* @param script the script to execute.
34+
* @param keys any keys that need to be passed to the script.
35+
* @param args any args that need to be passed to the script.
36+
* @return The return value of the script or {@literal null} if {@link RedisScript#getResultType()} is
37+
* {@literal null}, likely indicating a throw-away status reply (i.e. "OK")
3838
*/
3939
<T> T execute(RedisScript<T> script, List<K> keys, Object... args);
4040

4141
/**
4242
* Executes the given {@link RedisScript}, using the provided {@link RedisSerializer}s to serialize the script
4343
* arguments and result.
4444
*
45-
* @param script The script to execute
46-
* @param argsSerializer The {@link RedisSerializer} to use for serializing args
47-
* @param resultSerializer The {@link RedisSerializer} to use for serializing the script return value
48-
* @param keys Any keys that need to be passed to the script
49-
* @param args Any args that need to be passed to the script
50-
* @return The return value of the script or null if {@link RedisScript#getResultType()} is null, likely indicating a
51-
* throw-away status reply (i.e. "OK")
45+
* @param script the script to execute.
46+
* @param argsSerializer The {@link RedisSerializer} to use for serializing args.
47+
* @param resultSerializer The {@link RedisSerializer} to use for serializing the script return value.
48+
* @param keys any keys that need to be passed to the script.
49+
* @param args any args that need to be passed to the script.
50+
* @return The return value of the script or {@literal null} if {@link RedisScript#getResultType()} is
51+
* {@literal null}, likely indicating a throw-away status reply (i.e. "OK")
5252
*/
5353
<T> T execute(RedisScript<T> script, RedisSerializer<?> argsSerializer, RedisSerializer<T> resultSerializer,
5454
List<K> keys, Object... args);

0 commit comments

Comments
 (0)