我正在尝试开发用于这两种功能的Lua脚本-脚本LOAD/EVALSHA和函数LOAD/FCALL (Redis7.0的新特性)。
正如我现在所理解的--我所需要的只是找出执行上下文--如果脚本被调用为EVALSHA与函数加载。
local function myfunction(KEYS, ARGV)
-- do useful stuff
end
if running_as_evalsha then
--called by EVALSHA
--Redis 6.x version (no function support)
--redis-cli -x script load < myscript.lua
--evalsha 30d00b1eee6b536de87503593446e879578d31e2 1 key1 arg1
myfunction(KEYS, ARGV)
else
--called by FUNCTION LOAD
--Version for Redis 7.0 with function support
--cat myscript.lua | redis-cli -p 7000 -x FUNCTION LOAD Lua mylib REPLACE
--127.0.0.1:7000> FCALL myfunction 1 key1 arg1
redis.register_function('myfunction', myfunction)
end我在这里可以用什么做running_as_evalsha?(编辑)
发布于 2022-02-03 14:42:03
下面是我从Redis人员那里得到的答案:您可以检查您是否有redis.register_function,如果有,您在函数加载的上下文中,否则.
127.0.0.1:6379> eval "if redis.register_function == nil then redis.log(redis.LOG_NOTICE, 'eval') else redis.log(redis.LOG_NOTICE, 'function') end" 0
(nil)
127.0.0.1:6379> function load lua test replace "if redis.register_function == nil then redis.log(redis.LOG_NOTICE, 'eval') else redis.log(redis.LOG_NOTICE, 'function') end"
(error) ERR No functions registered第一个打印eval到日志,第二个打印function。
https://stackoverflow.com/questions/70956526
复制相似问题