YouTip LogoYouTip

Sets Sadd

# Redis Sadd Command [!(#) Redis Sets](#) The Redis SADD command adds one or more member elements to a set. Member elements already existing in the set will be ignored. If the set key does not exist, a new set containing only the added elements as members will be created. If the key exists but is not of type set, an error is returned. **Note:** Prior to Redis version 2.4, SADD accepted only 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 elements that were ignored. ### 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 Sets](#)
← Sets ScardRedis Sets β†’