Skip to main content
Add one or more members to a set stored at key. Members that already exist in the set are ignored. If the key does not exist, a new set is created.

Usage

await redis.sadd(key, member, ...members);

Parameters

key
string
required
The key of the set
member
TData
required
The first member to add to the set
members
TData[]
Additional members to add to the set

Response

result
number
The number of elements that were added to the set, not including elements already present

Examples

Add a single member

const result = await redis.sadd("myset", "hello");
console.log(result); // 1

Add multiple members

const result = await redis.sadd("fruits", "apple", "banana", "orange");
console.log(result); // 3

Add duplicate members

await redis.sadd("colors", "red", "blue");
const result = await redis.sadd("colors", "red", "green");
console.log(result); // 1 (only "green" was added)

Using with custom types

const result = await redis.sadd("numbers", 1, 2, 3, 4, 5);
console.log(result); // 5