Redis Sadd Command

Redis Set

The Redis Sadd command adds one or more member elements to a set, and member elements that already exist in the set are ignored.

If the set key does not exist, a set is created containing only the added element as a member.

When the set key is not of set type, an error is returned.

Note:Before Redis version 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 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"

Redis Set

Other Extensions