0
0
Redisquery~20 mins

Lua script syntax in Redis - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Redis Lua Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What does this Redis Lua script return?
Consider this Lua script run inside Redis:
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])
AError: wrong number of arguments
Bnil
C0
D"OK"
Attempts:
2 left
💡 Hint
The SET command returns a simple string reply when successful.
📝 Syntax
intermediate
2: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?
Aredis.call('INCR', KEYS[1])
Bredis.call('INCR', ARGV[1])
Credis.call('INCR')
Dredis.call('INCR', KEYS)
Attempts:
2 left
💡 Hint
The INCR command requires exactly one key argument.
🔧 Debug
advanced
2:00remaining
Why does this Lua script cause an error in Redis?
Given this script:
local val = redis.call('GET', KEYS[1])
return val + 1

What error will it cause and why?
Redis
local val = redis.call('GET', KEYS[1])
return val + 1
AAttempt to perform arithmetic on a nil value error
BSyntax error: unexpected symbol near '+'
CAttempt to perform arithmetic on a string value error
DNo error, returns incremented value
Attempts:
2 left
💡 Hint
redis.call('GET', key) returns a string or nil, not a number.
🧠 Conceptual
advanced
2: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?
AKEYS holds keys to access; ARGV holds additional arguments; separation helps Redis optimize command execution.
BKEYS holds values; ARGV holds keys.
CKEYS and ARGV both hold keys but in different formats.
DKEYS holds all arguments; ARGV is unused in scripts.
Attempts:
2 left
💡 Hint
Think about how Redis needs to know which keys a script will access.
optimization
expert
2: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?
ACall redis.call('INCR', key) 100 times in separate scripts.
BUse a single Lua script with a loop calling redis.call('INCR', key) for each key.
CUse redis.pcall inside the script to increment keys concurrently.
DUse a Lua script that builds a multi-command string and calls redis.call once.
Attempts:
2 left
💡 Hint
Lua scripts run atomically and reduce network round-trips.