Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Set | 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
Set

One of the key characteristics of a set is that it does not allow duplicate values. When you add a new element to a set, if the element already exists, it won't be added again.

Sets are commonly used for storing unique values, such as user IDs, IP addresses, or any other data where duplicates must be avoided.

Practical Use of Sets in Redis

Basic Commands for Working with Sets

Redis sets come with several commands that make it easy to add, remove, and check elements

Adding and Removing Elements

The SADD command adds elements to a set, ignoring duplicates, and the SREM command removes elements from a set.

Checking for an Element and Retrieving All Elements

To check if a specific element is in a set, use the SISMEMBER command, which returns 1 if the element is present and 0 if it's not. To get all elements of the set, use the SMEMBERS command.

Getting Information About the Set

To get the number of elements in a set, use the SCARD command, which returns the number of elements in the set.

Operations with Multiple Sets

When working with multiple sets, you can use the commands SDIFF, SINTER, and SUNIONSDIFF returns elements that are in one set but not in the others, SINTER finds common elements across all specified sets, and SUNION returns the union of all elements from multiple sets.

1. What does the SADD command do in Redis?

2. Which command should you use to retrieve all elements from a set?

What does the `SADD` command do in Redis?

What does the SADD command do in Redis?

Selecione a resposta correta

Which command should you use to retrieve all elements from a set?

Which command should you use to retrieve all elements from a set?

Selecione a resposta correta

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 3. Capítulo 4
We're sorry to hear that something went wrong. What happened?
some-alt