0
0
Redisquery~20 mins

Why patterns guide Redis usage - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Redis Pattern Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why is it important to follow usage patterns in Redis?

Redis is a fast, in-memory database. Why do developers follow specific usage patterns when working with Redis?

ABecause patterns make Redis slower but more secure.
BBecause Redis only supports one data type and patterns help simulate others.
CBecause Redis automatically fixes bad usage without patterns.
DBecause Redis requires patterns to optimize memory and speed effectively.
Attempts:
2 left
💡 Hint

Think about how Redis stores data and what affects its performance.

query_result
intermediate
2:00remaining
What is the output of this Redis command sequence?

Given these Redis commands executed in order:

SET user:1 "Alice"
HSET user:1:stats visits 5
HINCRBY user:1:stats visits 1
GET user:1
HGET user:1:stats visits

What are the values returned by the GET and HGET commands?

A"Alice" and "5"
B"Alice" and "6"
Cnil and "6"
Dnil and nil
Attempts:
2 left
💡 Hint

Remember that HINCRBY increases the integer value of a hash field by 1.

📝 Syntax
advanced
2:00remaining
Which Redis command syntax correctly adds multiple members to a set?

Choose the correct Redis command to add members 'apple', 'banana', and 'cherry' to the set 'fruits'.

ASADD fruits apple banana cherry
BADD fruits apple banana cherry
CSADD fruits ['apple', 'banana', 'cherry']
DSET fruits apple banana cherry
Attempts:
2 left
💡 Hint

Recall the command used to add members to a set in Redis.

optimization
advanced
2:00remaining
How can you optimize Redis memory usage when storing user sessions?

You want to store user sessions in Redis efficiently. Which approach optimizes memory usage best?

AStore each session as a JSON string in a Redis string key.
BUse Redis sorted sets with session IDs as members and timestamps as scores.
CUse Redis hashes to store session fields separately under one key per session.
DStore all sessions in a single Redis list key.
Attempts:
2 left
💡 Hint

Think about how Redis hashes store multiple fields efficiently.

🔧 Debug
expert
3:00remaining
Why does this Redis Lua script cause an error?

Consider this Lua script run in Redis:

local count = redis.call('INCR', KEYS[1])
if count == 1 then
  redis.call('EXPIRE', KEYS[1], ARGV[1])
end
return count

When running with redis-cli --eval script.lua , 10, it returns an error. What is the cause?

AThe script uses KEYS[1] but no keys were passed to the command.
BEXPIRE requires the key to exist before setting expiration.
CINCR cannot be used inside Lua scripts.
DARGV[1] is a string and must be converted to number before EXPIRE.
Attempts:
2 left
💡 Hint

Check how keys and arguments are passed to Redis Lua scripts.