0
0
Redisquery~15 mins

SCARD for set size in Redis - Mini Project: Build & Apply

Choose your learning style9 modes available
Counting Unique Items with Redis SCARD
📖 Scenario: You are managing a small online store. You want to keep track of unique customers who have visited your website each day. You will use Redis sets to store customer IDs and then count how many unique customers visited on a particular day.
🎯 Goal: Build a Redis data structure to store unique customer IDs for a day and use the SCARD command to find out how many unique customers visited that day.
📋 What You'll Learn
Create a Redis set with a specific key for storing customer IDs
Add multiple customer IDs to the set
Use a variable to hold the key name for the set
Use the SCARD command to get the count of unique customers
Complete the Redis commands in the correct order
💡 Why This Matters
🌍 Real World
Tracking unique visitors or users is common in websites and apps to understand user engagement.
💼 Career
Knowing how to use Redis sets and SCARD helps in building efficient real-time analytics and user tracking systems.
Progress0 / 4 steps
1
Create a Redis set with customer IDs
Create a Redis set with the key "customers:2024-06-01" and add these customer IDs: "cust1", "cust2", "cust3" using the SADD command.
Redis
Need a hint?

Use the SADD command followed by the set key and the customer IDs separated by spaces.

2
Set a variable for the Redis set key
Create a variable called key and set it to the string "customers:2024-06-01" to hold the Redis set key.
Redis
Need a hint?

Use the SET command to create a variable named key with the value of the set key.

3
Add more customer IDs to the set
Use the SADD command to add two more customer IDs: "cust4" and "cust5" to the existing set.
Redis
Need a hint?

Use SADD with the same set key to add new customer IDs.

4
Get the count of unique customers with SCARD
Use the SCARD command to get the number of unique customers in the set.
Redis
Need a hint?

Use SCARD followed by the set key to get the count of unique members.