Class DefaultScriptExecutor<K>
java.lang.Object
org.springframework.data.redis.core.script.DefaultScriptExecutor<K>
- Type Parameters:
K- The type of keys that may be passed during script execution
- All Implemented Interfaces:
ScriptExecutor<K>
Default implementation of
ScriptExecutor. Optimizes performance by attempting to execute script first using
evalsha, then falling back to eval if Redis has not yet cached the script. Evalsha is not attempted if the script is
executed in a pipeline or transaction.- Author:
- Jennifer Hickey, Christoph Strobl, Thomas Darimont, Mark Paluch
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected <T> TdeserializeResult(RedisSerializer<T> resultSerializer, Object result) protected <T> Teval(RedisConnection connection, RedisScript<T> script, ReturnType returnType, int numKeys, byte[][] keysAndArgs, RedisSerializer<T> resultSerializer) <T extends @Nullable Object>
Texecute(@NonNull RedisScript<T> script, @NonNull List<@NonNull K> keys, @NonNull Object @NonNull ... args) Executes the givenRedisScript<T extends @Nullable Object>
Texecute(@NonNull RedisScript<T> script, @NonNull RedisSerializer<?> argsSerializer, @NonNull RedisSerializer<T> resultSerializer, @NonNull List<@NonNull K> keys, @NonNull Object @NonNull ... args) Executes the givenRedisScript, using the providedRedisSerializers to serialize the script arguments and result.protected byte[][]keysAndArgs(RedisSerializer argsSerializer, List<K> keys, Object[] args) protected @Nullable RedisSerializerprotected byte[]scriptBytes(RedisScript<?> script)
-
Constructor Details
-
DefaultScriptExecutor
- Parameters:
template- TheRedisTemplateto use
-
-
Method Details
-
execute
public <T extends @Nullable Object> T execute(@NonNull RedisScript<T> script, @NonNull List<@NonNull K> keys, @NonNull Object @NonNull ... args) Description copied from interface:ScriptExecutorExecutes the givenRedisScript- Specified by:
executein interfaceScriptExecutor<K>- Parameters:
script- the script to execute.keys- any keys that need to be passed to the script.args- any args that need to be passed to the script.- Returns:
- The return value of the script or null if
RedisScript.getResultType()is null, likely indicating a throw-away status reply (i.e. "OK")
-
execute
public <T extends @Nullable Object> T execute(@NonNull RedisScript<T> script, @NonNull RedisSerializer<?> argsSerializer, @NonNull RedisSerializer<T> resultSerializer, @NonNull List<@NonNull K> keys, @NonNull Object @NonNull ... args) Description copied from interface:ScriptExecutorExecutes the givenRedisScript, using the providedRedisSerializers to serialize the script arguments and result.- Specified by:
executein interfaceScriptExecutor<K>- Parameters:
script- the script to execute.argsSerializer- TheRedisSerializerto use for serializing args.resultSerializer- TheRedisSerializerto use for serializing the script return value.keys- any keys that need to be passed to the script.args- any args that need to be passed to the script.- Returns:
- The return value of the script or null if
RedisScript.getResultType()is null, likely indicating a throw-away status reply (i.e. "OK")
-
eval
protected <T> T eval(RedisConnection connection, RedisScript<T> script, ReturnType returnType, int numKeys, byte[][] keysAndArgs, RedisSerializer<T> resultSerializer) -
keysAndArgs
-
scriptBytes
-
deserializeResult
-
keySerializer
-