public class Script extends Object implements Comparable<Script>
A simple immutable holder class to hold a Redis Lua Script and its sha1 digest. A script Object is meant for scripts that are going to be used repeatedly which is normally the case. Ideally scripts should be static variables or Singleton POJOs containing scripts if loaded from a file on jvm start. A Script object is created using the static getInstance method.
A script Object should be used with a RedisCommand.EVALCHECK
pseudo command.
There is a flag for each Script maintained against each Redis Server. When an AsyncRedisConnection
processes an EVALCHECK command for the first time when the flag for the script is not set against the
server, it checks if the script is present on the Redis Server by using the SCRIPT EXISTS command on a
separate Redis Connection. If SCRIPT EXISTS returns 0 then the script is loaded using the SCRIPT LOAD command.
Then the flag for the script is set to indicate that the script is verified/loaded on the server after which
an EVALSHA is sent with the script digest as the first parameter. Subsequent EVALCHECK calls for the same
script on the same server will straight away translate to EVALSHA since the flag for the script is set
against the server.
A script Object can also be used instead of a String to specify the script for the EVAL, EVALSHA, SCRIPT LOAD and SCRIPT EXISTS commands though you do not need these commands if you use the EVALCHECK pseudo-command. The advantage of using a Script Object for these commands in case you have a need to use them is that the script is marked as loaded for the server once the command completes successfully which can be used by the EVALCHECK pseudo command.
This class also includes Script constants containing Scripts used in aredis.
Also note that EVALCHECK commands will start failing if a SCRIPT FLUSH command is executed on the Redis server since the jvm does not know that scripts have been cleared. In such cases the script all script statuses are cleared on detecting the failure and the subsequent EVALCHECK commands will go through.
Modifier and Type | Field and Description |
---|---|
static Script |
ADD_SCRIPT
Deprecated.
Since version 2.6.12 Redis has an enhanced SET command which has an NX and expiry option. So this script is not required.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(Script o) |
boolean |
equals(Object o) |
int |
getIndex()
Gets the identifying index of the script.
|
static Script |
getInstance(String s)
This static method must be used to create a Script Object.
|
String |
getScript()
Gets the script.
|
String |
getSha1sum()
Gets the SHA-1 digest of the script.
|
int |
hashCode() |
public static final Script ADD_SCRIPT
public static Script getInstance(String s)
s
- Redis scriptpublic int compareTo(Script o)
compareTo
in interface Comparable<Script>
public String getScript()
public String getSha1sum()
public int getIndex()
Copyright © 2013- Suresh Mahalingam. All Rights Reserved.