Redis Sets: SADD
SADD key member1 [member2]
Redis SADD command is used to add members to set stored at key. If the member already exists, then it is ignored. If the key does not exist, then a new set is created and members are added into it. If the value stored at key if not set, then an error is returned.
Syntax:
SADD KEY_NAME VALUE1..VALUEN
Available since
1.0.0.
Return Value
Integer reply, the number of elements that were added to the set, not including all the elements already present into the set.
Return Value Type
Integer
Example: Redis SADD
127.0.0.1:6379> SADD mycolor "White" (integer) 1 127.0.0.1:6379> SADD mycolor "Yellow" "Green" (integer) 2 127.0.0.1:6379> SADD mycolor "Red" "Blue" "Orange" (integer) 3 127.0.0.1:6379> SMEMBERS mycolor 1) "Yellow" 2) "White" 3) "Blue" 4) "Green" 5) "Red" 6) "Orange"
Example: Redis SADD : Not Allowed Duplicate Member
In the set, member can not be redundant.
127.0.0.1:6379> SADD mycolor "Orange" (integer) 0 127.0.0.1:6379> SADD mycolor "Orange" "Pink" (integer) 1 127.0.0.1:6379> SMEMBERS mycolor 1) "Blue" 2) "White" 3) "Yellow" 4) "Pink" 5) "Green" 6) "Red" 7) "Orange"
Previous:
RPUSHX
Next:
Redis Sorted Sets ZADD
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join