The basic Redis command for adding an item to a set is SADD. It takes a key and one or more members and adds them to the set stored at the given key.
For example, lets say that I wanted to create a set with the items apple, pear and banana. I could execute either of the following:
SADD fruit apple
SADD fruit pear
SADD fruit banana
or
SADD fruit apple pear banana
After executing either, I will have the set fruit with 3 items.
Attempting to add an item that is already in the set will have no effect. After setting up my fruit set using the code above, if I try to add apple again:
SADD fruit apple
Redis will attempt to add apple to the fruit set, but since it is already in the set nothing will change.
The result of the SADD command is always the number of items Redis added to a set. So attempting to re-add apple, will return a result of 0.
Member items in Redis are case sensitive, so apple and Apple are treated as two separate items.