0
0
Redisquery~20 mins

Lua vs transactions comparison in Redis - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Redis Lua vs Transactions Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Atomicity in Redis: Lua Scripts vs Transactions

Which statement best describes the atomicity guarantee when using Lua scripts compared to Redis transactions?

ALua scripts and transactions both guarantee atomicity only if the MULTI command is used inside the script.
BTransactions in Redis are fully atomic, but Lua scripts can be interrupted by other commands causing partial execution.
CBoth Lua scripts and transactions execute commands one by one without atomic guarantees.
DLua scripts execute atomically, ensuring all commands run as a single unit without interruption, while transactions may allow other commands to interleave between MULTI and EXEC.
Attempts:
2 left
💡 Hint

Think about how Redis handles command execution inside Lua scripts versus MULTI/EXEC blocks.

query_result
intermediate
2:00remaining
Result of Concurrent Writes: Lua Script vs Transaction

Given two clients concurrently incrementing the same Redis key, which approach prevents race conditions?

Client 1 uses a Lua script to increment the key. Client 2 uses MULTI/EXEC transaction commands to increment the key.

What is the expected behavior?

ANeither Lua scripts nor transactions prevent race conditions; external locking is required.
BThe Lua script ensures increments are atomic and race conditions are prevented; the transaction may allow race conditions if commands overlap.
CBoth Lua scripts and transactions prevent race conditions equally by locking the key during execution.
DTransactions prevent race conditions by queuing commands, but Lua scripts do not provide any concurrency control.
Attempts:
2 left
💡 Hint

Consider how Redis executes Lua scripts and transactions in the context of concurrent clients.

📝 Syntax
advanced
2:00remaining
Identify the Correct Lua Script Syntax for Atomic Increment

Which Lua script correctly increments a Redis key atomically?

Redis
local current = redis.call('GET', KEYS[1])
local new = tonumber(current) + 1
redis.call('SET', KEYS[1], new)
return new
A
local current = redis.call('GET', KEYS[1])
local new = tonumber(current) + 1
redis.call('SET', KEYS[1], tostring(new))
return new
B
local current = redis.call('GET', KEYS[1])
local new = current + 1
redis.call('SET', KEYS[1], new)
return new
C
local current = redis.call('GET', KEYS[1])
local new = tonumber(current) + 1
redis.call('SET', KEYS[1], new)
return new
D
local current = redis.call('GET', KEYS[1])
local new = tonumber(current) + 1
redis.call('SET', KEYS[1], new)
return tostring(new)
Attempts:
2 left
💡 Hint

Remember Redis stores strings, so the value set must be a string.

optimization
advanced
2:00remaining
Optimizing Multiple Commands: Lua Script vs Transaction

You want to execute multiple Redis commands atomically and efficiently. Which approach is generally faster and why?

AUsing a transaction with MULTI/EXEC is faster because it pipelines commands and executes them in batch.
BBoth approaches have the same performance because Redis processes commands sequentially regardless of method.
CUsing a Lua script is faster because it runs all commands server-side in one call, reducing network overhead and ensuring atomicity.
DUsing multiple separate commands without transactions or scripts is faster due to parallel execution.
Attempts:
2 left
💡 Hint

Think about network round-trips and server-side execution.

🔧 Debug
expert
2:00remaining
Debugging a Redis Transaction Failure

A Redis transaction using MULTI/EXEC fails silently and does not apply any commands. Which of the following is the most likely cause?

AOne of the commands inside the transaction is invalid or causes an error, causing EXEC to abort all commands.
BThe transaction was not started with the MULTI command, so EXEC has no commands to execute.
CThe client did not wait for the EXEC reply, so the commands were executed but the client missed the response.
DRedis transactions do not support atomic execution, so commands are applied partially and silently fail.
Attempts:
2 left
💡 Hint

Consider how Redis handles errors inside transactions.