public async Task<RedisResult> Test() {
//EVAL string lua = @"local result={} for i, v in ipairs(KEYS) do result[i] = redis.call('hgetall',v) end return result"; var res1 = LuaScript.GetCachedScriptCount(); var res = await _client.ScriptEvaluateAsync(lua, new RedisKey[] { "people:1", "people:2", "people:3" });
//EVALSHA
var prepared = LuaScript.Prepare(lua); var loaded = await prepared.LoadAsync( RedisConnection.GenerateConnection.GetServer(RedisConnection.GenerateConnection.GetEndPoints().First())); var res2 = await loaded.EvaluateAsync(_client, new RedisKey[] { "people:1", "people:2", "people:3" }); var res3 = LuaScript.GetCachedScriptCount(); var res4 = await loaded.EvaluateAsync(_client, new RedisKey[] { "people:1", "people:2", "people:3" }); return res; }
如上代码,使用EVAL方式执行LUA没问题,正常返回。
使用第二段EVALSHA方式返回为空。不报错
使用stackexchange.redis官方的方式写的呀,方式一模一样的呢。
有使用过stackexchange.redis的EVALSHA方式执行LUA的园友帮忙分享下经验,和分析下错误。