Latest web development tutorials

Redis Sadd command

Redis set (Set)

Redis Sadd command of one or more members of the elements are added to the collection, a collection of elements already present in the members will be ignored.

If the set key does not exist, create a collection that contains only element added as members.

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

Note: In previous versions Redis2.4, SADD accepts only individual members value.

grammar

redis Sadd basic command syntax is as follows:

redis 127.0.0.1:6379> SADD KEY_NAME VALUE1..VALUEN

Available versions

> = 1.0.0

return value

It is added to the number of new elements in the collection, not including the neglected element.

Examples

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 (Set)