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>

@NullUnmarked 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.
Author:
Jennifer Hickey, Christoph Strobl, Thomas Darimont, Mark Paluch
  • Constructor Details

    • DefaultScriptExecutor

      public DefaultScriptExecutor(@NonNull RedisTemplate<K,?> template)
      Parameters:
      template - The RedisTemplate to 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: 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 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: 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 @Nullable RedisSerializer keySerializer()