0
0
Redisquery~30 mins

Real-time notification pattern in Redis - Mini Project: Build & Apply

Choose your learning style9 modes available
Real-time Notification Pattern with Redis
📖 Scenario: You are building a simple real-time notification system for a social media app. Users receive notifications when someone likes their post.
🎯 Goal: Create a Redis data structure to store notifications, configure a threshold for unread notifications, implement the logic to add new notifications, and finalize the setup to mark notifications as read.
📋 What You'll Learn
Create a Redis list called notifications:user123 with three initial notifications
Add a variable max_unread set to 5 to limit unread notifications
Write a Redis command to add a new notification to notifications:user123
Write a Redis command to trim the list to keep only the latest max_unread notifications
💡 Why This Matters
🌍 Real World
Real-time notifications are essential in social media apps, messaging platforms, and online marketplaces to keep users engaged and informed instantly.
💼 Career
Understanding how to use Redis lists and commands like LPUSH and LTRIM is valuable for backend developers working on scalable, real-time systems.
Progress0 / 4 steps
1
DATA SETUP: Create initial notifications list
Create a Redis list called notifications:user123 and add these three notifications exactly: 'Like from Alice', 'Like from Bob', 'Like from Charlie' using LPUSH commands.
Redis
Need a hint?

Use LPUSH to add items to the Redis list notifications:user123. Add each notification as a separate command.

2
CONFIGURATION: Set maximum unread notifications
Create a variable called max_unread and set it to 5 to limit the number of unread notifications stored.
Redis
Need a hint?

Assign the number 5 to a variable named max_unread to represent the maximum unread notifications.

3
CORE LOGIC: Add a new notification
Use LPUSH to add a new notification 'Like from Dave' to the Redis list notifications:user123.
Redis
Need a hint?

Use LPUSH to add the new notification 'Like from Dave' to the list notifications:user123.

4
COMPLETION: Trim the notifications list
Use the LTRIM command to keep only the latest max_unread notifications in the list notifications:user123. Use the range 0 to max_unread - 1.
Redis
Need a hint?

Use LTRIM notifications:user123 0 4 to keep only the first 5 notifications (index 0 to 4).