Skip to main content
Remove one or more members from a set stored at key. Members that do not exist in the set are ignored. If the key does not exist, it is treated as an empty set and the command returns 0.

Usage

await redis.srem(key, ...members);

Parameters

key
string
required
The key of the set
members
TData[]
required
One or more members to remove from the set

Response

result
number
The number of members that were removed from the set, not including non-existing members

Examples

Remove a single member

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

Remove multiple members

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

Remove non-existing members

await redis.sadd("colors", "red", "blue");
const result = await redis.srem("colors", "green", "yellow");
console.log(result); // 0

Remove from non-existing set

const result = await redis.srem("nonexistent", "member");
console.log(result); // 0