I'm trying to use StackExchange.Redis on Azure WebApp and need to run some Lua scripts.
The recommended way is to load the scripts to the server but I have difficulty understanding the correct pattern.
The way I think it should be done is on WebApp startup:
LuaScript luaScript = LuaScript.Prepare(scriptString);
var endpoints = redis.GetEndPoints();
var endpoint = endpoints[0];
IServer server = redis.GetServer(endpoint);
LoadedLuaScript loadedScript = luaScript.Load(server);
Then keep the LoadedLuaScript for later use (together with the ConnectionMultiplexer). Then later when I want to run the Lua script:
IDatabase db = redis.GetDatabase();
db.ScriptEvaluate(loadedScript);
Is this the correct way?
As Azure can have more than one Redis node, should I run the luaScript.Load for each endpoint and keep only one of them for later use? i.e.:
LuaScript luaScript = LuaScript.Prepare(script);
var endpoints = redis.GetEndPoints();
LoadedLuaScript loadedScript;
foreach (var endpoint in endpoints)
{
IServer server = redis.GetServer(endpoint);
loadedScript = luaScript.Load(server);
}
return loadedScript;