Class LuaScript
- Namespace
- StackExchange.Redis
- Assembly
- StackExchange.Redis.StrongName.dll
Represents a Lua script that can be executed on Redis.
Unlike normal Redis Lua scripts, LuaScript 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 LuaScript
- Inheritance
-
LuaScript
- Inherited Members
Properties
ExecutableScript
The Lua script that will actually be sent to Redis for execution.
All @-prefixed parameter names have been replaced at this point.
public string ExecutableScript { get; }
Property Value
OriginalScript
The original Lua script that was used to create this.
public string OriginalScript { get; }
Property Value
Methods
Evaluate(IDatabase, object, RedisKey?, CommandFlags)
Evaluates this LuaScript against the given database, extracting parameters from the passed in object if any.
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 LuaScript against the given database, extracting parameters from the passed in object if any.
public Task<RedisResult> EvaluateAsync(IDatabaseAsync db, object ps = null, RedisKey? withKeyPrefix = null, CommandFlags flags = CommandFlags.None)
Parameters
db
IDatabaseAsyncps
objectwithKeyPrefix
RedisKey?flags
CommandFlags
Returns
~LuaScript()
Finalizer, used to prompt cleanups of the script cache when a LuaScript reference goes out of scope.
protected ~LuaScript()
GetCachedScriptCount()
Returns the number of cached LuaScripts.
public static int GetCachedScriptCount()
Returns
Load(IServer, CommandFlags)
Loads this LuaScript into the given IServer so it can be run with it's SHA1 hash, instead of passing the full script on each Evaluate or EvaluateAsync call.
Note: the FireAndForget command flag cannot be set
public LoadedLuaScript Load(IServer server, CommandFlags flags = CommandFlags.None)
Parameters
server
IServerflags
CommandFlags
Returns
LoadAsync(IServer, CommandFlags)
Loads this LuaScript into the given IServer so it can be run with it's SHA1 hash, instead of passing the full script on each Evaluate or EvaluateAsync call.
Note: the FireAndForget command flag cannot be set
public Task<LoadedLuaScript> LoadAsync(IServer server, CommandFlags flags = CommandFlags.None)
Parameters
server
IServerflags
CommandFlags
Returns
Prepare(string)
Prepares a Lua script with named parameters to be run against any Redis instance.
public static LuaScript Prepare(string script)
Parameters
script
string
Returns
PurgeCache()
Invalidates the internal cache of LuaScript objects. Existing LuaScripts will continue to work, but future calls to LuaScript.Prepare return a new LuaScript instance.
public static void PurgeCache()