0
0
Redisquery~10 mins

Lua vs transactions comparison in Redis - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to start a Redis transaction.

Redis
redis.call('[1]')
Drag options to blanks, or click blank then click option'
AMULTI
BEXEC
CWATCH
DDISCARD
Attempts:
3 left
💡 Hint
Common Mistakes
Using EXEC instead of MULTI to start the transaction.
Using WATCH which is for monitoring keys, not starting transactions.
2fill in blank
medium

Complete the Lua script to atomically increment a key by 1.

Redis
return redis.call('[1]', KEYS[1]) + 1
Drag options to blanks, or click blank then click option'
AGET
BINCR
CSET
DDEL
Attempts:
3 left
💡 Hint
Common Mistakes
Using GET and adding 1 in Lua which is not atomic.
Using SET which overwrites the value.
3fill in blank
hard

Fix the error in the Lua script to ensure atomic increment.

Redis
local val = redis.call('[1]', KEYS[1])
if not val then
  redis.call('[2]', KEYS[1], 1)
  return 1
end
return redis.call('[3]', KEYS[1])
Drag options to blanks, or click blank then click option'
AGET
BSET
CINCR
DDEL
Attempts:
3 left
💡 Hint
Common Mistakes
Using DEL which deletes the key instead of setting or incrementing.
Using GET instead of INCR for incrementing.
4fill in blank
hard

Fill both blanks to watch a key and start a transaction.

Redis
redis.call('[1]', KEYS[1])
redis.call('[2]')
Drag options to blanks, or click blank then click option'
AWATCH
BMULTI
CEXEC
DDISCARD
Attempts:
3 left
💡 Hint
Common Mistakes
Using EXEC before MULTI.
Using DISCARD which cancels the transaction.
5fill in blank
hard

Fill all three blanks to execute a transaction with error handling.

Redis
redis.call('[1]')
local success = redis.call('[2]')
if not success then
  redis.call('[3]')
end
Drag options to blanks, or click blank then click option'
AMULTI
BEXEC
CDISCARD
DWATCH
Attempts:
3 left
💡 Hint
Common Mistakes
Using WATCH instead of DISCARD to cancel.
Calling EXEC before MULTI.