Challenge - 5 Problems
Redis Lua Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
What does this Redis Lua script return?
Consider this Lua script run inside Redis:
What is the output if the key does not exist before?
return redis.call('SET', KEYS[1], ARGV[1])What is the output if the key does not exist before?
Redis
return redis.call('SET', KEYS[1], ARGV[1])
Attempts:
2 left
💡 Hint
The SET command returns a simple string reply when successful.
✗ Incorrect
The redis.call('SET', key, value) command returns the string "OK" when it successfully sets the key.
📝 Syntax
intermediate2:00remaining
Which Lua script syntax is correct for incrementing a key's value?
You want to increment the integer value stored at a key using Redis Lua script. Which option is syntactically correct?
Attempts:
2 left
💡 Hint
The INCR command requires exactly one key argument.
✗ Incorrect
The INCR command increments the value stored at the key specified by KEYS[1]. ARGV is for arguments, not keys.
🔧 Debug
advanced2:00remaining
Why does this Lua script cause an error in Redis?
Given this script:
What error will it cause and why?
local val = redis.call('GET', KEYS[1])
return val + 1What error will it cause and why?
Redis
local val = redis.call('GET', KEYS[1]) return val + 1
Attempts:
2 left
💡 Hint
redis.call('GET', key) returns a string or nil, not a number.
✗ Incorrect
redis.call('GET', ...) returns a string or nil. Lua cannot add a number to a string without conversion, so it raises an error.
🧠 Conceptual
advanced2:00remaining
What is the purpose of KEYS and ARGV in Redis Lua scripts?
In Redis Lua scripting, what do KEYS and ARGV represent and why are they separated?
Attempts:
2 left
💡 Hint
Think about how Redis needs to know which keys a script will access.
✗ Incorrect
KEYS contains the keys the script will access, ARGV contains other arguments. This separation helps Redis know which keys are involved for replication and sharding.
❓ optimization
expert2:00remaining
How to optimize a Redis Lua script that increments multiple keys atomically?
You want to increment 100 keys atomically in Redis using Lua. Which approach is best for performance?
Attempts:
2 left
💡 Hint
Lua scripts run atomically and reduce network round-trips.
✗ Incorrect
A single Lua script looping over keys and calling redis.call('INCR', key) is efficient and atomic, minimizing network overhead.