Class LoadedLuaScript
- Namespace
- StackExchange.Redis
- Assembly
- StackExchange.Redis.StrongName.dll
Represents a Lua script that can be executed on Redis.
Unlike LuaScript, LoadedLuaScript sends the hash of it's ExecutableScript to Redis rather than pass the whole script on each call. This requires that the script be loaded into Redis before it is used.
To create a LoadedLuaScript first create a LuaScript via LuaScript.Prepare(string), then call Load(IServer, CommandFlags) on the returned LuaScript.
Unlike normal Redis Lua scripts, LoadedLuaScript can have named parameters (prefixed by a @). Public fields and properties of the passed in object are treated as parameters.
Parameters of type RedisKey are sent to Redis as KEY (http://redis.io/commands/eval) in addition to arguments, so as to play nicely with Redis Cluster.
All members of this class are thread safe.
public sealed class LoadedLuaScript
- Inheritance
-
LoadedLuaScript
- Inherited Members
Properties
ExecutableScript
The script that will actually be sent to Redis for execution.
public string ExecutableScript { get; }
Property Value
Hash
The SHA1 hash of ExecutableScript.
This is sent to Redis instead of ExecutableScript during Evaluate and EvaluateAsync calls.
public byte[] Hash { get; }
Property Value
- byte[]
OriginalScript
The original script that was used to create this LoadedLuaScript.
public string OriginalScript { get; }
Property Value
Methods
Evaluate(IDatabase, object, RedisKey?, CommandFlags)
Evaluates this LoadedLuaScript against the given database, extracting parameters for the passed in object if any.
This method sends the SHA1 hash of the ExecutableScript instead of the script itself. If the script has not been loaded into the passed Redis instance it will fail.
public RedisResult Evaluate(IDatabase db, object ps = null, RedisKey? withKeyPrefix = null, CommandFlags flags = CommandFlags.None)
Parameters
db
IDatabaseps
objectwithKeyPrefix
RedisKey?flags
CommandFlags
Returns
EvaluateAsync(IDatabaseAsync, object, RedisKey?, CommandFlags)
Evaluates this LoadedLuaScript against the given database, extracting parameters for the passed in object if any.
This method sends the SHA1 hash of the ExecutableScript instead of the script itself. If the script has not been loaded into the passed Redis instance it will fail.
public Task<RedisResult> EvaluateAsync(IDatabaseAsync db, object ps = null, RedisKey? withKeyPrefix = null, CommandFlags flags = CommandFlags.None)
Parameters
db
IDatabaseAsyncps
objectwithKeyPrefix
RedisKey?flags
CommandFlags