diff --git a/src/main/antora/modules/ROOT/pages/redis/scripting.adoc b/src/main/antora/modules/ROOT/pages/redis/scripting.adoc index 436c50d11c..42411fbd9c 100644 --- a/src/main/antora/modules/ROOT/pages/redis/scripting.adoc +++ b/src/main/antora/modules/ROOT/pages/redis/scripting.adoc @@ -34,7 +34,7 @@ public class Example { RedisScript script; public boolean checkAndSet(String expectedValue, String newValue) { - return redisOperations.execute(script, singletonList("key"), asList(expectedValue, newValue)); + return redisOperations.execute(script, List.of("key"), expectedValue, newValue); } } ---- @@ -52,7 +52,7 @@ public class Example { RedisScript script; public Flux checkAndSet(String expectedValue, String newValue) { - return redisOperations.execute(script, singletonList("key"), asList(expectedValue, newValue)); + return redisOperations.execute(script, List.of("key"), expectedValue, newValue); } } ---- diff --git a/src/main/java/org/springframework/data/redis/core/ReactiveRedisOperations.java b/src/main/java/org/springframework/data/redis/core/ReactiveRedisOperations.java index c02d1eea81..4f123c9cbc 100644 --- a/src/main/java/org/springframework/data/redis/core/ReactiveRedisOperations.java +++ b/src/main/java/org/springframework/data/redis/core/ReactiveRedisOperations.java @@ -429,6 +429,20 @@ default Flux execute(RedisScript script, List keys) { return execute(script, keys, Collections.emptyList()); } + /** + * Executes the given {@link RedisScript} + * + * @param script The script to execute. Must not be {@literal null}. + * @param keys keys that need to be passed to the script. Must not be {@literal null}. + * @param args args that need to be passed to the script. Must not be {@literal null}. + * @return result value of the script {@link Flux#empty()} if {@link RedisScript#getResultType()} is {@literal null}, + * likely indicating a throw-away status reply (i.e. "OK"). + * @since 3.4 + */ + default Flux execute(RedisScript script, List keys, Object... args) { + return execute(script, keys, Arrays.asList(args)); + } + /** * Executes the given {@link RedisScript} * diff --git a/src/main/java/org/springframework/data/redis/core/script/ReactiveScriptExecutor.java b/src/main/java/org/springframework/data/redis/core/script/ReactiveScriptExecutor.java index b9b765d96f..6cd520f394 100644 --- a/src/main/java/org/springframework/data/redis/core/script/ReactiveScriptExecutor.java +++ b/src/main/java/org/springframework/data/redis/core/script/ReactiveScriptExecutor.java @@ -18,6 +18,7 @@ import reactor.core.publisher.Flux; import java.nio.ByteBuffer; +import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -30,8 +31,8 @@ *

* Streams of methods returning {@code Mono} or {@code Flux} are terminated with * {@link org.springframework.dao.InvalidDataAccessApiUsageException} when - * {@link org.springframework.data.redis.serializer.RedisElementReader#read(ByteBuffer)} returns {@code null} for a - * particular element as Reactive Streams prohibit the usage of {@code null} values. + * {@link org.springframework.data.redis.serializer.RedisElementReader#read(ByteBuffer)} returns {@literal null} for a + * particular element as Reactive Streams prohibit the usage of {@literal null} values. * * @author Mark Paluch * @author Christoph Strobl @@ -67,8 +68,22 @@ default Flux execute(RedisScript script, List keys) { * Executes the given {@link RedisScript} * * @param script The script to execute. Must not be {@literal null}. - * @param keys Any keys that need to be passed to the script. Must not be {@literal null}. - * @param args Any args that need to be passed to the script. Can be {@literal empty}. + * @param keys any keys that need to be passed to the script. Must not be {@literal null}. + * @param args any args that need to be passed to the script. Can be {@literal empty}. + * @return The return value of the script or {@link Flux#empty()} if {@link RedisScript#getResultType()} is + * {@literal null}, likely indicating a throw-away status reply (i.e. "OK") + * @since 3.4 + */ + default Flux execute(RedisScript script, List keys, Object... args) { + return execute(script, keys, Arrays.asList(args)); + } + + /** + * Executes the given {@link RedisScript} + * + * @param script The script to execute. Must not be {@literal null}. + * @param keys any keys that need to be passed to the script. Must not be {@literal null}. + * @param args any args that need to be passed to the script. Can be {@literal empty}. * @return The return value of the script or {@link Flux#empty()} if {@link RedisScript#getResultType()} is * {@literal null}, likely indicating a throw-away status reply (i.e. "OK") */ @@ -79,8 +94,8 @@ default Flux execute(RedisScript script, List keys) { * arguments and result. * * @param script The script to execute. must not be {@literal null}. - * @param keys Any keys that need to be passed to the script - * @param args Any args that need to be passed to the script + * @param keys any keys that need to be passed to the script. + * @param args any args that need to be passed to the script. * @param argsWriter The {@link RedisElementWriter} to use for serializing args. Must not be {@literal null}. * @param resultReader The {@link RedisElementReader} to use for serializing the script return value. Must not be * {@literal null}. diff --git a/src/main/java/org/springframework/data/redis/core/script/ScriptExecutor.java b/src/main/java/org/springframework/data/redis/core/script/ScriptExecutor.java index b7b658a7e4..953f27fbb1 100644 --- a/src/main/java/org/springframework/data/redis/core/script/ScriptExecutor.java +++ b/src/main/java/org/springframework/data/redis/core/script/ScriptExecutor.java @@ -30,11 +30,11 @@ public interface ScriptExecutor { /** * Executes the given {@link RedisScript} * - * @param script The script to execute - * @param keys Any keys that need to be passed to the script - * @param args Any args that need to be passed to the script - * @return The return value of the script or null if {@link RedisScript#getResultType()} is null, likely indicating a - * throw-away status reply (i.e. "OK") + * @param script the script to execute. + * @param keys any keys that need to be passed to the script. + * @param args any args that need to be passed to the script. + * @return The return value of the script or {@literal null} if {@link RedisScript#getResultType()} is + * {@literal null}, likely indicating a throw-away status reply (i.e. "OK") */ T execute(RedisScript script, List keys, Object... args); @@ -42,13 +42,13 @@ public interface ScriptExecutor { * Executes the given {@link RedisScript}, using the provided {@link RedisSerializer}s to serialize the script * arguments and result. * - * @param script The script to execute - * @param argsSerializer The {@link RedisSerializer} to use for serializing args - * @param resultSerializer The {@link RedisSerializer} to use for serializing the script return value - * @param keys Any keys that need to be passed to the script - * @param args Any args that need to be passed to the script - * @return The return value of the script or null if {@link RedisScript#getResultType()} is null, likely indicating a - * throw-away status reply (i.e. "OK") + * @param script the script to execute. + * @param argsSerializer The {@link RedisSerializer} to use for serializing args. + * @param resultSerializer The {@link RedisSerializer} to use for serializing the script return value. + * @param keys any keys that need to be passed to the script. + * @param args any args that need to be passed to the script. + * @return The return value of the script or {@literal null} if {@link RedisScript#getResultType()} is + * {@literal null}, likely indicating a throw-away status reply (i.e. "OK") */ T execute(RedisScript script, RedisSerializer argsSerializer, RedisSerializer resultSerializer, List keys, Object... args);