Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Challenge: Managing User Interests | Data Types in Redis
Introduction to Redis
course content

Conteúdo do Curso

Introduction to Redis

Introduction to Redis

1. Redis Fundamentals
2. The Essential Redis Commands
3. Data Types in Redis
4. Advanced Features and Security
5. Caching with Redis and Spring Boot

book
Challenge: Managing User Interests

Imagine you are developing a feature for an application that tracks user interests. Information about each user is stored in Redis as a set. Each user has a unique collection of interests.

  1. Add the interests for each user to their respective sets:

    • user:1:interests: "music", "movies", "sports";
    • user:2:interests: "sports", "travel", "reading";
    • user:3:interests: "reading", "music", "cooking".
  2. Check if User 1 is interested in "travel" and if User 2 is interested in "sports";

  3. Identify the common interests of User 1 and User 2;

  4. Find the interests of User 1 that are not shared by User 2;

  5. Create a list of all unique interests shared by User 1, User 2, and User 3;

  6. User 3 has stopped being interested in "music." Remove this interest from their set;

  7. Display the list of interests for each user after performing these operations.

1. Add interests for each user to their respective sets:

SADD user:1:interests "music" "movies" "sports"
SADD user:2:interests "sports" "travel" "reading"
SADD user:3:interests "reading" "music" "cooking"

2. Verify if a specific interest exists in a user's set:

SISMEMBER user:1:interests "travel"    # result: 0 (User 1 is not interested)
SISMEMBER user:2:interests "sports"   # result: 1 (User 2 is interested)

3. Retrieve shared interests between two users:

SINTER user:1:interests user:2:interests   # result: ["sports"]

4. Get interests of one user that are not shared by another:

SDIFF user:1:interests user:2:interests   # result: ["music", "movies"]

5. Create a full list of unique interests from all users:

SUNION user:1:interests user:2:interests user:3:interests   # result: ["music", "movies", "sports", "travel", "reading", "cooking"]

6. Delete an interest from a user's set:

SREM user:3:interests "music"

7. Retrieve the updated sets of interests for each user:

SMEMBERS user:1:interests   # result: ["music", "movies", "sports"]
SMEMBERS user:2:interests   # result: ["sports", "travel", "reading"]
SMEMBERS user:3:interests   # result: ["reading", "cooking"]

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 3. Capítulo 5

Pergunte à IA

expand

Pergunte à IA

ChatGPT

Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo

course content

Conteúdo do Curso

Introduction to Redis

Introduction to Redis

1. Redis Fundamentals
2. The Essential Redis Commands
3. Data Types in Redis
4. Advanced Features and Security
5. Caching with Redis and Spring Boot

book
Challenge: Managing User Interests

Imagine you are developing a feature for an application that tracks user interests. Information about each user is stored in Redis as a set. Each user has a unique collection of interests.

  1. Add the interests for each user to their respective sets:

    • user:1:interests: "music", "movies", "sports";
    • user:2:interests: "sports", "travel", "reading";
    • user:3:interests: "reading", "music", "cooking".
  2. Check if User 1 is interested in "travel" and if User 2 is interested in "sports";

  3. Identify the common interests of User 1 and User 2;

  4. Find the interests of User 1 that are not shared by User 2;

  5. Create a list of all unique interests shared by User 1, User 2, and User 3;

  6. User 3 has stopped being interested in "music." Remove this interest from their set;

  7. Display the list of interests for each user after performing these operations.

1. Add interests for each user to their respective sets:

SADD user:1:interests "music" "movies" "sports"
SADD user:2:interests "sports" "travel" "reading"
SADD user:3:interests "reading" "music" "cooking"

2. Verify if a specific interest exists in a user's set:

SISMEMBER user:1:interests "travel"    # result: 0 (User 1 is not interested)
SISMEMBER user:2:interests "sports"   # result: 1 (User 2 is interested)

3. Retrieve shared interests between two users:

SINTER user:1:interests user:2:interests   # result: ["sports"]

4. Get interests of one user that are not shared by another:

SDIFF user:1:interests user:2:interests   # result: ["music", "movies"]

5. Create a full list of unique interests from all users:

SUNION user:1:interests user:2:interests user:3:interests   # result: ["music", "movies", "sports", "travel", "reading", "cooking"]

6. Delete an interest from a user's set:

SREM user:3:interests "music"

7. Retrieve the updated sets of interests for each user:

SMEMBERS user:1:interests   # result: ["music", "movies", "sports"]
SMEMBERS user:2:interests   # result: ["sports", "travel", "reading"]
SMEMBERS user:3:interests   # result: ["reading", "cooking"]

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 3. Capítulo 5
some-alt