Yes, LUA
script is a best solution in case of EVALSHA
call:
- You are working woth redis asynchronous. So
LUA
helps you to reduce number of code and code readability. LUA
case is faster becouse of reduce network communication.
I think you can write your code with just 2 commands. You do not need exists
in your code.
local path = KEYS[1]
local resourcesPrefix = ARGV[1]
local collectionsPrefix = ARGV[2]
local ret
set ret = redis.call('get',resourcesPrefix..path)
if ret then
return ret
end
set ret = redis.call('smembers',collectionsPrefix..path)
if ret then
return ret
end
return "notFound"