Challenge - 5 Problems
Lua EVAL Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate1:30remaining
Output of a simple Lua script with EVAL
What is the output of this Redis EVAL command?
EVAL "return ARGV[1] .. ARGV[2]" 0 Hello WorldRedis
EVAL "return ARGV[1] .. ARGV[2]" 0 Hello World
Attempts:
2 left
💡 Hint
Remember that ARGV is a list of arguments passed after the key count, and concatenation in Lua uses .. operator.
✗ Incorrect
The Lua script concatenates ARGV[1] and ARGV[2] without spaces, so the output is "HelloWorld".
📝 Syntax
intermediate1:30remaining
Identify the syntax error in Lua script for EVAL
Which option contains a syntax error when used as the Lua script in Redis EVAL?
Attempts:
2 left
💡 Hint
Check for missing or mismatched parentheses in the Lua code.
✗ Incorrect
Option A is missing a closing parenthesis after KEYS[1], causing a syntax error.
❓ optimization
advanced2:00remaining
Optimizing Lua script to increment multiple keys
You want to increment the values of multiple keys atomically using EVAL. Which Lua script is the most efficient?
Attempts:
2 left
💡 Hint
Use KEYS array to loop over keys, not ARGV.
✗ Incorrect
Option A loops over all keys passed in KEYS and increments each one, which is efficient and scalable.
🧠 Conceptual
advanced1:30remaining
Understanding KEYS and ARGV in EVAL
In Redis EVAL command, what is the main difference between KEYS and ARGV?
Attempts:
2 left
💡 Hint
Think about how Redis separates keys from other parameters for scripting.
✗ Incorrect
KEYS contains the list of keys the script will access, while ARGV contains other arguments passed to the script.
🔧 Debug
expert1:30remaining
Debugging a Lua script that returns nil unexpectedly
Given this EVAL command:
If the key 'mykey' does not exist, what will the script return?
EVAL "return redis.call('get', KEYS[1])" 1 mykeyIf the key 'mykey' does not exist, what will the script return?
Redis
EVAL "return redis.call('get', KEYS[1])" 1 mykey
Attempts:
2 left
💡 Hint
Consider what Redis returns when getting a non-existent key.
✗ Incorrect
Redis returns nil when a key does not exist, so the Lua script returns nil.