0
0
Redisquery~30 mins

Key design patterns in Redis - Mini Project: Build & Apply

Choose your learning style9 modes available
Redis Key Design Patterns
📖 Scenario: You are building a simple user session management system using Redis. Redis stores data as keys and values, and how you design your keys is very important for easy access and maintenance.In this project, you will create keys following common Redis key design patterns to store user session data.
🎯 Goal: Build Redis keys using common design patterns to store and organize user session information clearly and efficiently.
📋 What You'll Learn
Create keys using a clear naming pattern with colons as separators
Use a prefix to group related keys
Include user IDs in keys to identify user-specific data
Store session data as simple string values
Demonstrate how to set and get these keys
💡 Why This Matters
🌍 Real World
Redis key design patterns help organize data clearly, making it easy to find and manage user sessions or other grouped data in real applications.
💼 Career
Understanding key design is essential for backend developers and database administrators working with Redis to build scalable and maintainable systems.
Progress0 / 4 steps
1
Create user session keys with prefixes
Create three Redis keys for user sessions with the prefix session and user IDs 1001, 1002, and 1003. The keys should be named exactly as session:1001, session:1002, and session:1003. Assign each key a string value representing the session token: token_abc, token_def, and token_ghi respectively.
Redis
Need a hint?

Use the SET command to create keys with the pattern session:userID.

2
Add a configuration key for session expiration time
Create a Redis key named config:session_timeout and set its value to 3600 to represent session expiration time in seconds.
Redis
Need a hint?

Use the SET command with the key config:session_timeout and value 3600.

3
Retrieve a user session token using the key
Write a Redis command to get the session token for user ID 1002 using the key session:1002.
Redis
Need a hint?

Use the GET command with the key session:1002 to retrieve the token.

4
Set expiration for user session keys
Add expiration of 3600 seconds to each user session key: session:1001, session:1002, and session:1003 using the EXPIRE command.
Redis
Need a hint?

Use the EXPIRE command with each session key and the timeout value 3600.