Shiva Profile picture
https://t.co/aQ1DGvQ1Fo .Passionate Tech AI enthusiast & polyglot developer. Co-founder of https://t.co/CUIVlEBXXC, ReaderMonk & Mumbai.rb. Tweets are my own. #buildinpublic

Mar 12, 2023, 12 tweets

Redis Part 3 is here! Today, we'll be exploring the power of Redis 'Sets'. #redis #thread 🧵
If you haven't read the previous thread about the list, check it out

Redis Sets are a unique way to store your data! They allow for an unordered collection of strings with no duplicates. Perfect for managing sets of items without worrying about repetition

Let's dive in with an example, Say we want to give one lucky user a year of free membership to Nooli. With Redis Sets, users can enroll in the giveaway but only once, preventing duplicates. Easy and efficient!

SADD - command adds an element to set

SADD <KEY> <MEMBER>

SISMEMBER - command is used to check if an element is present in the set. If it's present it returns 1 else 0

SISMEMBER <KEY> <MEMBER>

SMEMBERS - command lists all the elements in the set.

SMEMBERS <KEY>

SCARD - set cardinality, determines the number of elements in a set

SCARD <KEY>

SREM - command removes the given elements

SREM <KEY> <MEMBER>

SPOP - removes a random element/s from the set, to remove more than one element pass the count after the key

SPOP <KEY> <COUNT>

Bonus:
SINTER: Gives intersection between two sets.
Let's say in Nooli, we need to find users who signed up for a giveaway but haven't activated their account? We can use SINTER between two sets: user giveaways & inactive users. Reach out to those users and get them activated!

Thanks for reading this thread! If you're interested in learning more about Redis, follow me @_rshiva
& don't forget to retweet the 1st thread to help other devs.
I'm passionate about #buildinginpublic,
web development, &
sharing my learnings with others.
Stay tuned for more

@noolify thread

Share this Scrolly Tale with your friends.

A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.

Keep scrolling