0
0
Redisquery~20 mins

Session storage pattern in Redis - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Redis Session Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
1: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?
Redis
SET session:123 user1
EXPIRE session:123 10
TTL session:123
A-2
B-1
C10
D0
Attempts:
2 left
💡 Hint
TTL returns the remaining time to live in seconds for a key with expiration.
📝 Syntax
intermediate
1: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?
ASETEX session:456 1800 user2
BSET session:456 user2 EX 1800
CSET session:456 user2 PX 1800000
DEXPIRE session:456 1800 SET user2
Attempts:
2 left
💡 Hint
SETEX sets a key with expiration in seconds in one command.
optimization
advanced
2: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?
AStore session data as a Redis hash and update fields with HSET commands
BStore session data as a JSON string and overwrite with SET on every update
CStore session data in multiple keys per field and update keys individually
DStore session data in a Redis list and push updates to the list
Attempts:
2 left
💡 Hint
Hashes allow updating parts of data without rewriting the whole value.
🔧 Debug
advanced
2: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?
Redis
SET session:789 user3
EXPIRE session:789 60
SET session:789 user3_updated
AThe key was deleted before expiration
BEXPIRE command was not executed correctly
CRedis does not support expiration on string keys
DThe last SET command removes the expiration from the key
Attempts:
2 left
💡 Hint
Setting a key again resets its expiration unless specified.
🧠 Conceptual
expert
2: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?
ARedis supports complex SQL queries on session data
BRedis provides faster read/write performance due to in-memory storage
CRedis sessions never expire unless manually deleted
DRedis automatically encrypts session data for security
Attempts:
2 left
💡 Hint
Think about speed and how Redis stores data.