Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Redis Sadd Command

Redis Sadd Command

Redis Set

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

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

Returns an error when the set key is not of set type.

**Note:** Before 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 Version

= 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