...

/

Storing Set in Redis: Insertion Commands

Storing Set in Redis: Insertion Commands

Learn about the commands to store sets in Redis database.

In an earlier lesson, we looked at storing lists of elements in Redis. The problem with a list is that it allows duplicate elements. If we need to add unique elements, we can use a Set instead of a List.

Redis internally uses a hash table to store the elements as a Set. The image below depicts how elements are stored in a Set. There is no particular order. The elements are stored randomly, and repetition is not allowed.

Some of the commands used to handle sets in Redis are listed below. Let’s suppose we need to maintain a list of fruits available in a grocery store. A given fruit cannot be repeated in the list.

SADD command

To add an element into a set in Redis, we use the SADD ...