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> T
deserializeResult
(RedisSerializer<T> resultSerializer, Object result) protected <T> T
eval
(RedisConnection connection, RedisScript<T> script, ReturnType returnType, int numKeys, byte[][] keysAndArgs, RedisSerializer<T> resultSerializer) <T> T
execute
(RedisScript<T> script, List<K> keys, Object... args) Executes the givenRedisScript
<T> T
execute
(RedisScript<T> script, RedisSerializer<?> argsSerializer, RedisSerializer<T> resultSerializer, List<K> keys, Object... args) Executes the givenRedisScript
, using the providedRedisSerializer
s to serialize the script arguments and result.protected byte[][]
keysAndArgs
(RedisSerializer argsSerializer, List<K> keys, Object[] args) protected RedisSerializer
protected byte[]
scriptBytes
(RedisScript<?> script)
-
Constructor Details
-
DefaultScriptExecutor
- Parameters:
template
- TheRedisTemplate
to use
-
-
Method Details
-
execute
Description copied from interface:ScriptExecutor
Executes the givenRedisScript
- Specified by:
execute
in 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> T execute(RedisScript<T> script, RedisSerializer<?> argsSerializer, RedisSerializer<T> resultSerializer, List<K> keys, Object... args) Description copied from interface:ScriptExecutor
Executes the givenRedisScript
, using the providedRedisSerializer
s to serialize the script arguments and result.- Specified by:
execute
in interfaceScriptExecutor<K>
- Parameters:
script
- the script to execute.argsSerializer
- TheRedisSerializer
to use for serializing args.resultSerializer
- TheRedisSerializer
to 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
-