0
0
Redisquery~30 mins

SUNION, SINTER, SDIFF set operations in Redis - Mini Project: Build & Apply

Choose your learning style9 modes available
Using SUNION, SINTER, and SDIFF Set Operations in Redis
📖 Scenario: You are managing a Redis database for a small online bookstore. You have sets representing different categories of books that customers like. You want to find combined, common, and unique interests among these categories.
🎯 Goal: Build Redis commands to create sets for book categories and use SUNION, SINTER, and SDIFF to find combined, common, and unique books liked by customers.
📋 What You'll Learn
Create three Redis sets named fiction, mystery, and science with specified book titles.
Create a variable to hold the set names for operations.
Use SUNION to find all unique books liked in any category.
Use SINTER to find books liked in all categories.
Use SDIFF to find books liked in fiction but not in mystery or science.
💡 Why This Matters
🌍 Real World
Managing user preferences or categories in Redis sets is common in recommendation systems and online stores.
💼 Career
Understanding Redis set operations helps in building fast, efficient data queries for real-time applications.
Progress0 / 4 steps
1
Create Redis sets for book categories
Create three Redis sets named fiction, mystery, and science with these exact members: fiction has 'The Great Gatsby', '1984', 'To Kill a Mockingbird'; mystery has 'Gone Girl', 'The Girl with the Dragon Tattoo', '1984'; science has 'A Brief History of Time', 'The Selfish Gene', '1984'. Use the SADD command for each set.
Redis
Need a hint?

Use SADD followed by the set name and the exact book titles in quotes.

2
Create a variable holding the set names
Create a Redis variable named categories that holds the names of the three sets: fiction, mystery, and science. Use the Redis command SET with the value as a space-separated string of the set names.
Redis
Need a hint?

Use SET categories "fiction mystery science" to store the set names as a string.

3
Use SUNION and SINTER to find combined and common books
Use the SUNION command with the sets fiction, mystery, and science to find all unique books liked by customers. Then use the SINTER command with the same sets to find books liked in all three categories.
Redis
Need a hint?

Use SUNION fiction mystery science and SINTER fiction mystery science commands.

4
Use SDIFF to find unique fiction books
Use the SDIFF command with fiction as the first set and mystery and science as the sets to subtract. This finds books liked in fiction but not in mystery or science.
Redis
Need a hint?

Use SDIFF fiction mystery science to find unique fiction books.