Challenge - 5 Problems
Lua Atomic Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
What is the output of this Lua script in Redis?
Consider the following Lua script executed in Redis:
What will be the output after running this script?
redis.call('SET', 'counter', 10)
local val = redis.call('INCRBY', 'counter', 5)
return valWhat will be the output after running this script?
Redis
redis.call('SET', 'counter', 10) local val = redis.call('INCRBY', 'counter', 5) return val
Attempts:
2 left
💡 Hint
Remember that INCRBY increases the value stored at the key by the given amount and returns the new value.
✗ Incorrect
The script sets 'counter' to 10, then increments it by 5 using INCRBY, which returns the new value 15.
📝 Syntax
intermediate2:00remaining
Which Lua script will cause a syntax error in Redis?
Identify the Lua script that will cause a syntax error when executed in Redis.
Attempts:
2 left
💡 Hint
Look for missing or misplaced parentheses.
✗ Incorrect
Option B is missing a closing parenthesis in the redis.call function, causing a syntax error.
❓ optimization
advanced2:00remaining
Which Lua script is the most efficient for incrementing a counter and returning its new value?
You want to increment a Redis key 'visits' atomically and get the updated value. Which script is the most efficient?
Attempts:
2 left
💡 Hint
Consider atomicity and number of Redis calls.
✗ Incorrect
Option A uses the atomic INCR command which increments and returns the new value in one call, making it most efficient.
🧠 Conceptual
advanced2:00remaining
Why are Lua scripts in Redis considered atomic?
Choose the best explanation for why Lua scripts executed in Redis are atomic.
Attempts:
2 left
💡 Hint
Think about how Redis handles commands and scripts internally.
✗ Incorrect
Redis executes Lua scripts sequentially, blocking other commands until the script finishes, ensuring atomicity.
🔧 Debug
expert2:00remaining
What error does this Lua script raise in Redis?
Given the Lua script:
What error will Redis return when executing this script?
local val = redis.call('INCRBY', 'counter', 'five')
return valWhat error will Redis return when executing this script?
Redis
local val = redis.call('INCRBY', 'counter', 'five') return val
Attempts:
2 left
💡 Hint
INCRBY expects a numeric increment value.
✗ Incorrect
Passing a non-numeric string 'five' to INCRBY causes Redis to return an error about invalid integer value.