Redis – Set Sadd Command

  • Post author:
  • Post category:Redis
  • Post comments:1 Comment

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

Return Value

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

Syntax

Following is the basic syntax of Redis SADD command.

redis 127.0.0.1:6379> SADD KEY_NAME VALUE1..VALUEN

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"

This Post Has One Comment

Leave a Reply