0
0
Redisquery~15 mins

SET with expiry (EX, PX) in Redis - Mini Project: Build & Apply

Choose your learning style9 modes available
Using Redis SET Command with Expiry (EX, PX)
📖 Scenario: You are managing a simple cache system for a website. You want to store user session tokens in Redis with an expiration time so that sessions automatically expire after some time.
🎯 Goal: Learn how to use the Redis SET command with expiration options EX (seconds) and PX (milliseconds) to store keys that expire automatically.
📋 What You'll Learn
Create a Redis key-value pair for a user session token
Set the key to expire after a certain number of seconds using EX
Set another key to expire after a certain number of milliseconds using PX
Verify the correct syntax for the SET command with expiry options
💡 Why This Matters
🌍 Real World
Web applications often store session tokens or cache data in Redis with expiry to automatically remove stale data.
💼 Career
Knowing how to set keys with expiry in Redis is essential for backend developers and DevOps engineers managing scalable, performant applications.
Progress0 / 4 steps
1
Create a Redis key for a user session token
Use the Redis SET command to create a key called session:user123 with the value token_abc123.
Redis
Need a hint?

Use SET key value to store a key-value pair in Redis.

2
Add expiry in seconds using EX option
Modify the SET command to set the key session:user123 with value token_abc123 to expire after 300 seconds using the EX option.
Redis
Need a hint?

Use EX seconds after the value to set expiry in seconds.

3
Create another key with expiry in milliseconds using PX option
Use the Redis SET command to create a key called session:user456 with value token_xyz789 that expires after 15000 milliseconds using the PX option.
Redis
Need a hint?

Use PX milliseconds after the value to set expiry in milliseconds.

4
Complete the Redis commands with expiry options
Ensure both keys session:user123 and session:user456 are set with their respective expiry options using the SET command with EX and PX.
Redis
Need a hint?

Both commands should include the expiry options exactly as shown.