Challenge - 5 Problems
Redis Session Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate1:30remaining
What is the output of this Redis command sequence?
Given these Redis commands executed in order:
1. SET session:123 user1
2. EXPIRE session:123 10
3. TTL session:123
What does the TTL command return immediately after setting the expiration?
1. SET session:123 user1
2. EXPIRE session:123 10
3. TTL session:123
What does the TTL command return immediately after setting the expiration?
Redis
SET session:123 user1 EXPIRE session:123 10 TTL session:123
Attempts:
2 left
💡 Hint
TTL returns the remaining time to live in seconds for a key with expiration.
✗ Incorrect
After setting an expiration of 10 seconds, TTL returns the remaining seconds before the key expires, which is 10 immediately after setting.
📝 Syntax
intermediate1:30remaining
Which Redis command syntax correctly stores a session with a 30-minute expiration?
You want to store a session key 'session:456' with value 'user2' that expires in 30 minutes. Which command is correct?
Attempts:
2 left
💡 Hint
SETEX sets a key with expiration in seconds in one command.
✗ Incorrect
SETEX key seconds value sets the key with expiration in seconds. Option A uses correct syntax.
❓ optimization
advanced2:00remaining
Which approach optimizes session storage for frequent updates in Redis?
You store user sessions in Redis and update session data frequently. Which approach is best to optimize performance and reduce network overhead?
Attempts:
2 left
💡 Hint
Hashes allow updating parts of data without rewriting the whole value.
✗ Incorrect
Using Redis hashes lets you update individual fields efficiently, reducing data transfer and improving performance.
🔧 Debug
advanced2:00remaining
Why does this Redis session expiration not work as expected?
You run these commands:
1. SET session:789 user3
2. EXPIRE session:789 60
3. SET session:789 user3_updated
After 60 seconds, the key still exists. Why?
1. SET session:789 user3
2. EXPIRE session:789 60
3. SET session:789 user3_updated
After 60 seconds, the key still exists. Why?
Redis
SET session:789 user3 EXPIRE session:789 60 SET session:789 user3_updated
Attempts:
2 left
💡 Hint
Setting a key again resets its expiration unless specified.
✗ Incorrect
A new SET command without expiration removes any previous expiration on the key.
🧠 Conceptual
expert2:30remaining
What is the main advantage of using Redis session storage over traditional database sessions?
Why do many web applications prefer Redis for session storage instead of storing sessions in a traditional relational database?
Attempts:
2 left
💡 Hint
Think about speed and how Redis stores data.
✗ Incorrect
Redis stores data in memory, making session reads and writes much faster than disk-based databases.