我正在尝试在 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 并只保留其中一个以供以后使用?IE:
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;