Skip to content

Commit

Permalink
Consistently accept varargs with Redis Scripting.
Browse files Browse the repository at this point in the history
Closes #3010
  • Loading branch information
mp911de committed Oct 10, 2024
1 parent 7bedd60 commit 31b6736
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/main/antora/modules/ROOT/pages/redis/scripting.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class Example {
RedisScript<Boolean> 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);
}
}
----
Expand All @@ -52,7 +52,7 @@ public class Example {
RedisScript<Boolean> script;
public Flux<Boolean> checkAndSet(String expectedValue, String newValue) {
return redisOperations.execute(script, singletonList("key"), asList(expectedValue, newValue));
return redisOperations.execute(script, List.of("key"), expectedValue, newValue);
}
}
----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,20 @@ default <T> Flux<T> execute(RedisScript<T> script, List<K> 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 <T> Flux<T> execute(RedisScript<T> script, List<K> keys, Object... args) {
return execute(script, keys, Arrays.asList(args));
}

/**
* Executes the given {@link RedisScript}
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -30,8 +31,8 @@
* <p>
* Streams of methods returning {@code Mono<K>} or {@code Flux<M>} 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
Expand Down Expand Up @@ -67,8 +68,22 @@ default <T> Flux<T> execute(RedisScript<T> script, List<K> 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 <T> Flux<T> execute(RedisScript<T> script, List<K> 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")
*/
Expand All @@ -79,8 +94,8 @@ default <T> Flux<T> execute(RedisScript<T> script, List<K> 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}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,25 @@ public interface ScriptExecutor<K> {
/**
* 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> T execute(RedisScript<T> script, List<K> keys, Object... args);

/**
* 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> T execute(RedisScript<T> script, RedisSerializer<?> argsSerializer, RedisSerializer<T> resultSerializer,
List<K> keys, Object... args);
Expand Down

0 comments on commit 31b6736

Please sign in to comment.