org.springframework.data.redis.core.script
Class DefaultScriptExecutor<K>

java.lang.Object
  extended by 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>

public class DefaultScriptExecutor<K>
extends Object
implements 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.


Constructor Summary
DefaultScriptExecutor(RedisTemplate<K,?> template)
           
 
Method Summary
protected
<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 given RedisScript
<T> T
execute(RedisScript<T> script, RedisSerializer<?> argsSerializer, RedisSerializer<T> resultSerializer, List<K> keys, Object... args)
          Executes the given RedisScript, using the provided RedisSerializers to serialize the script arguments and result.
protected  byte[][] keysAndArgs(RedisSerializer argsSerializer, List<K> keys, Object[] args)
           
protected  RedisSerializer keySerializer()
           
protected  byte[] scriptBytes(RedisScript<?> script)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultScriptExecutor

public DefaultScriptExecutor(RedisTemplate<K,?> template)
Parameters:
template - The RedisTemplate to use
Method Detail

execute

public <T> T execute(RedisScript<T> script,
                     List<K> keys,
                     Object... args)
Description copied from interface: ScriptExecutor
Executes the given RedisScript

Specified by:
execute in interface ScriptExecutor<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 given RedisScript, using the provided RedisSerializers to serialize the script arguments and result.

Specified by:
execute in interface ScriptExecutor<K>
Parameters:
script - The script to execute
argsSerializer - The RedisSerializer to use for serializing args
resultSerializer - The RedisSerializer 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

protected byte[][] keysAndArgs(RedisSerializer argsSerializer,
                               List<K> keys,
                               Object[] args)

scriptBytes

protected byte[] scriptBytes(RedisScript<?> script)

deserializeResult

protected <T> T deserializeResult(RedisSerializer<T> resultSerializer,
                                  Object result)

keySerializer

protected RedisSerializer keySerializer()