I’m trying to come up with the Lua script that would work with both - SCRIPT LOAD/EVALSHA and FUNCTION LOAD/FCALL (New feature of Redis 7.0).
As I understand it now - all i need is to figure out the execution context - if script is being called as EVALSHA vs. FUNCTION LOAD.
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
What can I use here as running_as_evalsha? (edited)