我正在尝试在Azure WebApp上使用StackExchange.Redis并需要运行一些Lua脚本。
建议的方式是将脚本加载到服务器上,但我难以理解正确的模式。
我认为应该在WebApp启动时完成:
LuaScript luaScript = LuaScript.Prepare(scriptString);
var endpoints = redis.GetEndPoints();
var endpoint = endpoints[0];
IServer server = redis.GetServer(endpoint);
LoadedLuaScript loadedScript = luaScript.Load(server);
然后将LoadedLuaScript保留以备后用(与ConnectionMultiplexer一起)。 稍后当我想运行Lua脚本时:
IDatabase db = redis.GetDatabase();
db.ScriptEvaluate(loadedScript);
这是正确的方式吗?
由于Azure可以拥有多个Redis节点,因此我是否应该为每个端点运行luaScript.Load,并仅保留一个供以后使用?即:
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;