0
0
Redisquery~10 mins

Transactions vs Lua scripts 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
BDISCARD
CWATCH
DEXEC
Attempts:
3 left
💡 Hint
Common Mistakes
Using EXEC to start a transaction instead of MULTI.
Using WATCH which is for monitoring keys, not starting transactions.
2fill in blank
medium

Complete the code to execute all commands queued in a Redis transaction.

Redis
redis.call('[1]')
Drag options to blanks, or click blank then click option'
AWATCH
BMULTI
CDISCARD
DEXEC
Attempts:
3 left
💡 Hint
Common Mistakes
Using MULTI instead of EXEC to run commands.
Using DISCARD which cancels the transaction.
3fill in blank
hard

Fix the error in the Lua script to atomically increment a key and return its new value.

Redis
local newVal = redis.call('INCR', '[1]')
return newVal
Drag options to blanks, or click blank then click option'
AINCR
Bcounter
CMULTI
DEXEC
Attempts:
3 left
💡 Hint
Common Mistakes
Using command names like MULTI or EXEC as key names.
Leaving the key name blank or incorrect.
4fill in blank
hard

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

Redis
redis.call('[1]', 'mykey')
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 instead of MULTI.
5fill in blank
hard

Fill all three blanks to write a Lua script that increments a key only if it has not changed since watching it.

Redis
redis.call('[1]', KEYS[1])
redis.call('[2]')
redis.call('INCR', KEYS[1])
local val = redis.call('[3]')
return val[1]
Drag options to blanks, or click blank then click option'
AWATCH
BMULTI
CEXEC
DDISCARD
Attempts:
3 left
💡 Hint
Common Mistakes
Using DISCARD instead of EXEC.
Not watching the key before starting the transaction.