0
0
Redisquery~10 mins

Lua script syntax in Redis - Interactive Code Practice

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

Complete the code to set a key "name" with value "Alice" in Redis using Lua.

Redis
redis.call('[1]', 'name', 'Alice')
Drag options to blanks, or click blank then click option'
Aget
Bset
Cdel
Dexists
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'get' instead of 'set' will try to retrieve a value, not store it.
Using 'del' deletes keys, which is not what we want here.
2fill in blank
medium

Complete the code to increment the integer value stored at key "counter" by 1.

Redis
redis.call('[1]', 'counter')
Drag options to blanks, or click blank then click option'
Aincr
Bdecr
Cappend
Dset
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'decr' will decrease the value instead of increasing it.
Using 'append' is for strings, not numbers.
3fill in blank
hard

Fix the error in the code to get the value of key "user".

Redis
local val = redis.call('[1]', 'user')
Drag options to blanks, or click blank then click option'
Adel
Bset
Cget
Dexists
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'set' tries to assign a value, not get it.
Using 'del' deletes the key, which is not intended.
4fill in blank
hard

Fill both blanks to check if key "session" exists and delete it if it does.

Redis
if redis.call('[1]', 'session') == 1 then
  redis.call('[2]', 'session')
end
Drag options to blanks, or click blank then click option'
Aexists
Bdel
Cget
Dset
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'get' to check existence returns the value, not a boolean.
Using 'set' instead of 'del' will overwrite the key.
5fill in blank
hard

Fill both blanks to set key "count" to 10 only if it does not exist, then get its value.

Redis
redis.call('[1]', 'count', 10)
local val = redis.call('[2]', 'count')
return val
Drag options to blanks, or click blank then click option'
Asetnx
Bget
Cset
Ddel
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'set' instead of 'setnx' overwrites the key unconditionally.
Using 'del' deletes the key, which is not intended.