Redis SADD Command
The Redis SADD command adds one or more member elements to a set. Member elements that already exist in the set will be ignored.
If the set key does not exist, a new set containing only the added elements as members is created.
An error is returned if the set key is not of the set type.
Note: Prior to Redis 2.4, SADD only accepted a single member value.
Syntax
The basic syntax of the redis SADD command is as follows:
redis 127.0.0.1:6379> SADD KEY_NAME VALUE1..VALUEN
Available Versions
= 1.0.0
Return Value
The number of new elements added to the set, excluding any ignored elements.
Example
redis 127.0.0.1:6379> SADD myset "hello"
(integer) 1
redis 127.0.0.1:6379> SADD myset "foo"
(integer) 1
redis 127.0.0.1:6379> SADD myset "hello"
(integer) 0
redis 127.0.0.1:6379> SMEMBERS myset
1) "hello"
2) "foo"