0
0
Redisquery~30 mins

Unique visitor tracking with sets in Redis - Mini Project: Build & Apply

Choose your learning style9 modes available
Unique Visitor Tracking with Sets in Redis
📖 Scenario: You run a website and want to track unique visitors each day. You will use Redis sets to store visitor IDs because sets automatically keep only unique values.
🎯 Goal: Build a Redis data structure that stores unique visitor IDs for a specific day and allows you to count how many unique visitors came that day.
📋 What You'll Learn
Create a Redis set key for visitors on a specific date
Add visitor IDs to the set
Use a variable for the date key
Count the number of unique visitors using the set's cardinality
💡 Why This Matters
🌍 Real World
Websites and apps often need to count unique visitors daily to understand traffic and user engagement.
💼 Career
Knowing how to use Redis sets for unique tracking is useful for backend developers and data engineers working with real-time analytics.
Progress0 / 4 steps
1
Create a Redis set key for today's visitors
Create a Redis key called visitors:2023-06-01 to represent the set of unique visitors for June 1, 2023. Use the Redis command SADD to add visitor IDs user1, user2, and user3 to this set.
Redis
Need a hint?

Use SADD followed by the key name and the visitor IDs separated by spaces.

2
Use a variable for the date key
Create a Redis variable called date_key and set it to visitors:2023-06-01. This variable will hold the key name for the visitor set.
Redis
Need a hint?

Use the SET command to create a variable holding the key name.

3
Add more visitor IDs using the date_key variable
Use the SADD command with the variable date_key to add visitor IDs user4 and user5 to the set.
Redis
Need a hint?

Use SADD with the key name to add new visitors. Redis CLI does not support variable substitution like $date_key.

4
Count the number of unique visitors
Use the SCARD command with the variable date_key to get the count of unique visitors for June 1, 2023.
Redis
Need a hint?

SCARD returns the number of unique elements in a set.