0
0
Redisquery~10 mins

Cache warming strategies 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-value pair in Redis cache.

Redis
SET "user:1001" "John Doe" [1]
Drag options to blanks, or click blank then click option'
AXX
BNX
CPX
DEX
Attempts:
3 left
💡 Hint
Common Mistakes
Using EX or PX which set expiration but do not control existence.
Using XX which sets only if key exists, not for warming.
2fill in blank
medium

Complete the code to preload multiple keys into Redis cache using a pipeline.

Redis
redis.pipeline()[1]
Drag options to blanks, or click blank then click option'
A.execute()
B.flushall()
C.get('user:1')
D.set('user:1', 'Alice')
Attempts:
3 left
💡 Hint
Common Mistakes
Calling execute immediately without adding commands.
Using flushall which clears the cache.
3fill in blank
hard

Fix the error in the Lua script that preloads cache keys only if they don't exist.

Redis
if redis.call('EXISTS', [1]) == 0 then redis.call('SET', [1], ARGV[1]) end
Drag options to blanks, or click blank then click option'
AKEYS[2]
BARGV[1]
CKEYS[1]
DARGV[2]
Attempts:
3 left
💡 Hint
Common Mistakes
Using ARGV for keys causes errors.
Using wrong index in KEYS or ARGV arrays.
4fill in blank
hard

Fill both blanks to create a Redis command that preloads keys with expiration only if they don't exist.

Redis
SET [1] [2] NX EX 3600
Drag options to blanks, or click blank then click option'
Auser:2001
BJohn
Cuser:3001
DAlice
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping key and value positions.
Using keys that do not match the value.
5fill in blank
hard

Fill all three blanks to write a Lua script that warms cache by setting multiple keys with values only if they don't exist.

Redis
for i, key in ipairs([1]) do if redis.call('EXISTS', key) == 0 then redis.call('SET', key, [2][i]) end end return [3]
Drag options to blanks, or click blank then click option'
A{'user:1', 'user:2', 'user:3'}
B{'Alice', 'Bob', 'Carol'}
Ctrue
Dfalse
Attempts:
3 left
💡 Hint
Common Mistakes
Using mismatched keys and values.
Returning false instead of true.
Not using tables for keys and values.