0
0
Redisquery~20 mins

EVALSHA for cached scripts in Redis - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Redis EVALSHA Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What is the output of this Redis EVALSHA command?
Given the Lua script SHA1 hash is abcd1234 and the script returns the sum of two keys' integer values, what will be the output of this command if key1=5 and key2=3?
Redis
EVALSHA abcd1234 2 key1 key2
ATypeError
B8
CError: NOSCRIPT No matching script. Please use EVAL.
D5 3
Attempts:
2 left
💡 Hint
EVALSHA runs a cached Lua script by its SHA1 hash and returns the script's result.
🧠 Conceptual
intermediate
2:00remaining
Why use EVALSHA instead of EVAL in Redis?
Choose the best reason why Redis clients prefer using EVALSHA over EVAL after the script is loaded.
AEVALSHA is faster because it uses the cached script by its SHA1 hash, avoiding re-sending the script code.
BEVALSHA can run scripts without any keys or arguments.
CEVALSHA automatically updates the script if it changes on the server.
DEVALSHA returns the script source code instead of executing it.
Attempts:
2 left
💡 Hint
Think about network efficiency and script caching.
📝 Syntax
advanced
2:00remaining
Which EVALSHA command syntax is correct to run a script with 3 keys and 2 arguments?
Select the correct Redis EVALSHA command syntax to run a cached script with SHA1 hash f1e2d3c4, passing 3 keys and 2 arguments.
AEVALSHA f1e2d3c4 5 key1 key2 key3 arg1 arg2
BEVALSHA f1e2d3c4 key1 key2 key3 3 arg1 arg2
CEVALSHA f1e2d3c4 3 key1 key2 key3 arg1 arg2
DEVALSHA f1e2d3c4 2 key1 key2 key3 arg1 arg2
Attempts:
2 left
💡 Hint
Remember the syntax: EVALSHA ... ...
🔧 Debug
advanced
2:00remaining
What error occurs if you run EVALSHA with an unknown SHA1 hash?
You run EVALSHA deadbeef 1 key1 arg1 but the script is not cached on the server. What error message will Redis return?
ASyntaxError: invalid command
BOK
CTypeError: missing arguments
DError: NOSCRIPT No matching script. Please use EVAL.
Attempts:
2 left
💡 Hint
Think about what happens when the script is not found in cache.
optimization
expert
3:00remaining
How to optimize repeated Lua script execution in Redis using EVALSHA?
You have a Lua script that you run many times with different keys and arguments. Which approach best optimizes performance?
ALoad the script once with EVAL, then run it repeatedly with EVALSHA using the cached SHA1 hash.
BRun the script every time with EVAL to ensure the latest version is used.
CUse EVALSHA without loading the script first; Redis will auto-load it.
DStore the script in a Redis string and call it by GET command.
Attempts:
2 left
💡 Hint
Consider network traffic and script caching benefits.