Complete the code to load a Lua script into Redis and get its SHA1 hash.
sha1 = redis.call('SCRIPT', '[1]', script)
The LOAD command loads a Lua script into Redis and returns its SHA1 hash.
Complete the code to execute a cached Lua script by its SHA1 hash.
result = redis.call('[1]', sha1, 0)
The EVALSHA command executes a cached Lua script by its SHA1 hash.
Fix the error in the code to check if a script is cached before running it.
if redis.call('SCRIPT', '[1]', sha1) == 1 then redis.call('EVALSHA', sha1, 0) else sha1 = redis.call('SCRIPT', 'LOAD', script) redis.call('EVALSHA', sha1, 0) end
The SCRIPT EXISTS command checks if a script is cached by its SHA1 hash.
Fill both blanks to load a script only if it is not cached, then execute it.
if redis.call('SCRIPT', '[1]', sha1) == 0 then sha1 = redis.call('SCRIPT', '[2]', script) end redis.call('EVALSHA', sha1, 0)
Use SCRIPT EXISTS to check if the script is cached, and SCRIPT LOAD to load it if not.
Fill all three blanks to cache a script, check its existence, and execute it safely.
sha1 = redis.call('SCRIPT', '[1]', script) if redis.call('SCRIPT', '[2]', sha1) == 1 then redis.call('[3]', sha1, 0) else redis.call('EVAL', script, 0) end
First, SCRIPT LOAD caches the script and returns its SHA1. Then SCRIPT EXISTS checks if it is cached. If yes, EVALSHA runs the cached script safely.