Complete the code to set a key-value pair in Redis cache.
SET "user:1001" "John Doe" [1]
The NX option sets the key only if it does not already exist, which is useful for cache warming to avoid overwriting existing cache.
Complete the code to preload multiple keys into Redis cache using a pipeline.
redis.pipeline()[1]Using pipeline().set() allows batching multiple set commands to warm the cache efficiently.
Fix the error in the Lua script that preloads cache keys only if they don't exist.
if redis.call('EXISTS', [1]) == 0 then redis.call('SET', [1], ARGV[1]) end
In Redis Lua scripts, keys are passed via KEYS array. To check existence of the first key, use KEYS[1].
Fill both blanks to create a Redis command that preloads keys with expiration only if they don't exist.
SET [1] [2] NX EX 3600
The command sets key user:2001 with value John only if the key does not exist, with expiration of 3600 seconds.
Fill all three blanks to write a Lua script that warms cache by setting multiple keys with values only if they don't exist.
for i, key in ipairs([1]) do if redis.call('EXISTS', key) == 0 then redis.call('SET', key, [2][i]) end end return [3]
The script loops over keys {'user:1', 'user:2', 'user:3'} and sets their values from {'Alice', 'Bob', 'Carol'} only if keys don't exist, then returns true.