Class DefaultRedisScript<T>

java.lang.Object
org.springframework.data.redis.core.script.DefaultRedisScript<T>
Type Parameters:
T - The script result type. Should be one of Long, Boolean, List, or deserialized value type. Can be null if the script returns a throw-away status (i.e "OK")
All Implemented Interfaces:
InitializingBean, RedisScript<T>

public class DefaultRedisScript<T> extends Object implements RedisScript<T>, InitializingBean
Default implementation of RedisScript. Delegates to an underlying ScriptSource to retrieve script text and detect if script has been modified (and thus should have SHA1 re-calculated). This class is best used as a Singleton to avoid re-calculation of SHA1 on every script execution.
Author:
Jennifer Hickey, Christoph Strobl
  • Constructor Details

    • DefaultRedisScript

      public DefaultRedisScript()
      Creates a new DefaultRedisScript
    • DefaultRedisScript

      public DefaultRedisScript(String script)
      Creates a new DefaultRedisScript
      Parameters:
      script - must not be null.
      Since:
      2.0
    • DefaultRedisScript

      public DefaultRedisScript(String script, @Nullable Class<T> resultType)
      Creates a new DefaultRedisScript
      Parameters:
      script - must not be null.
      resultType - can be null.
  • Method Details

    • afterPropertiesSet

      public void afterPropertiesSet()
      Specified by:
      afterPropertiesSet in interface InitializingBean
    • getSha1

      public String getSha1()
      Specified by:
      getSha1 in interface RedisScript<T>
      Returns:
      The SHA1 of the script, used for executing Redis evalsha command.
    • getResultType

      @Nullable public Class<T> getResultType()
      Specified by:
      getResultType in interface RedisScript<T>
      Returns:
      The script result type. Should be one of Long, Boolean, List, or deserialized value type. null if the script returns a throw-away status (i.e "OK").
    • getScriptAsString

      public String getScriptAsString()
      Specified by:
      getScriptAsString in interface RedisScript<T>
      Returns:
      The script contents.
    • setResultType

      public void setResultType(@Nullable Class<T> resultType)
      Parameters:
      resultType - The script result type. Should be one of Long, Boolean, List, or deserialized value type. Can be null if the script returns a throw-away status (i.e "OK")
    • setScriptText

      public void setScriptText(String scriptText)
      Parameters:
      scriptText - The script text
    • setLocation

      public void setLocation(Resource scriptLocation)
      Parameters:
      scriptLocation - The location of the script
    • setScriptSource

      public void setScriptSource(ScriptSource scriptSource)
      Parameters:
      scriptSource - A @{link ScriptSource pointing to the script