Suggest an editImprove this articleRefine the answer for “What is Set in Redis?”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)A Set in Redis is an unordered collection of unique string values: every element is unique (duplicates aren't stored), order isn't fixed, and fast set operations are supported - union (`SUNION`), intersection (`SINTER`), difference (`SDIFF`). **Key point:** internally it's stored as an `intset` (for integers, up to 512 elements by default) or a `hashtable` (for strings or larger sets); it fits unique IDs, tags, subscribers, and fast membership checks via `SISMEMBER`.Shown above the full answer for quick recall.Answer (EN)ImageA **Set** in Redis is an **unordered set of unique string values**. Every element is a Redis String, but with no duplicates and no preserved order. ### Main properties - Every element is unique (duplicates aren't stored). - Element order isn't fixed. - Fast set operations are supported, union, intersection, difference. - It fits storing unique values: IDs, tags, users, and so on. ### Example ```bash SADD users "anna" "ivan" "maria" SADD users "ivan" SMEMBERS users ``` Result: ```javascript 1) "anna" 2) "ivan" 3) "maria" ``` The second `"ivan"` add is ignored, the element already exists. ### Main commands | Command | Description | |---|---| | `SADD key value [value ...]` | add element(s) | | `SREM key value [value ...]` | remove element(s) | | `SMEMBERS key` | get every element in the set | | `SISMEMBER key value` | check whether a value exists | | `SCARD key` | the number of elements | | `SPOP key [count]` | remove and return a random element | | `SRANDMEMBER key [count]` | get a random element without removing it | | `SUNION key [key ...]` | union of sets | | `SINTER key [key ...]` | intersection of sets | | `SDIFF key [key ...]` | difference of sets | ### A union and intersection example ```bash SADD groupA "anna" "maria" SADD groupB "maria" "ivan" SUNION groupA groupB SINTER groupA groupB ``` Result: ```javascript SUNION → "anna", "maria", "ivan" SINTER → "maria" ``` ### Internal structure Redis stores sets in two formats: 1. **intset**, if every element is an integer and there aren't many (up to 512 elements by default). 2. **hashtable**, if there are more elements or they include strings. intset saves memory, hashtable provides fast insertion and lookup. ### Uses - Storing unique user IDs or tokens. - Lists of subscribers or members with no duplicates. - Fast membership checks (`SISMEMBER`). - Recommendation systems via set intersection (`SINTER`). - Counting unique visits or actions (`SCARD`).For the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.