> For the complete documentation index, see [llms.txt](https://gchandra.gitbook.io/big-data-and-tools-with-nosql/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gchandra.gitbook.io/big-data-and-tools-with-nosql/nosql/redis/data-structures/set.md).

# Set

A Redis set is an unordered collection of unique strings (members). You can use Redis sets to efficiently:

* Track unique items (e.g., track all unique IP addresses accessing a given blog post).
* Represent relations (e.g., the set of all users with a given role).
* Perform common set operations such as intersection, unions, and differences.

A Redis set is an unordered collection of unique strings (members). You can use Redis sets to efficiently:

* [`SADD`](https://redis.io/commands/sadd) adds a new member to a set.
* [`SREM`](https://redis.io/commands/srem) removes the specified member from the set.
* [`SISMEMBER`](https://redis.io/commands/sismember) tests a string for set membership.
* [`SINTER`](https://redis.io/commands/sinter) returns the set of members that two or more sets have in common (i.e., the intersection).
* [`SCARD`](https://redis.io/commands/scard) returns the size (a.k.a. cardinality) of a set.

```
SADD "user:userID1:followers" followerID1
SADD "user:userID1:followers" followerID2

SADD "user:userID2:followers" followerID1
SADD "user:userID2:followers" followerID3

-- Find the common followers between two users
SINTER "user:userID1:followers" "user:userID2:followers"

-- Get the SET values
SMEMBERS "user:userID1:followers"

-- Gets the size of the set.
SCARD "user:userID1:followers"

-- Find out whether followerID1 is part of this set
SISMEMBER user:userID1:followers followerID1

```

**Use Cases**

**Real-time Analytics**: Track and display unique events or items, like products viewed in a session.

**ACLs (Access Control List):** Manage user access to certain features or commands.
