w3resource logo
Redis Tutorial

Redis Sets: SADD

SADD key member1 [member2]

Redis SADD command is used to add members to set stored at key. If the member already exists, then it is ignored. If the key does not exist, then a new set is created and members are added into it. If the value stored at key if not set, then an error is returned.



Available since


Return Value

Integer reply, the number of elements that were added to the set, not including all the elements already present into the set.

Return Value Type


Example: Redis SADD> SADD mycolor "White"
(integer) 1> SADD mycolor "Yellow" "Green"
(integer) 2> SADD mycolor "Red" "Blue" "Orange"
(integer) 3> SMEMBERS mycolor
1) "Yellow"
2) "White"
3) "Blue"
4) "Green"
5) "Red"
6) "Orange"

Example: Redis SADD : Not Allowed Duplicate Member

In the set, member can not be redundant.> SADD mycolor "Orange"
(integer) 0> SADD mycolor "Orange" "Pink"
(integer) 1> SMEMBERS mycolor
1) "Blue"
2) "White"
3) "Yellow"
4) "Pink"
5) "Green"
6) "Red"
7) "Orange"

ankara escort ankara escort ankara escort antalya escort alanya escort