Returns the members of the set resulting from the union of all the given sets. Keys that do not exist are considered to be empty sets.
Usage
await redis.sunion(key, ...keys);
Parameters
Additional set keys to union with
Response
An array containing the members of the resulting set (union of all sets)
Examples
Union of two sets
await redis.sadd("set1", "a", "b", "c");
await redis.sadd("set2", "c", "d", "e");
const result = await redis.sunion("set1", "set2");
console.log(result); // ["a", "b", "c", "d", "e"]
Union of multiple sets
await redis.sadd("skills:alice", "javascript", "python");
await redis.sadd("skills:bob", "python", "go");
await redis.sadd("skills:charlie", "java", "javascript");
const allSkills = await redis.sunion(
"skills:alice",
"skills:bob",
"skills:charlie"
);
console.log(allSkills); // ["javascript", "python", "go", "java"]
Combine tag sets
await redis.sadd("tags:frontend", "react", "vue", "angular");
await redis.sadd("tags:backend", "node", "django", "rails");
const allTags = await redis.sunion("tags:frontend", "tags:backend");
console.log(allTags);
// ["react", "vue", "angular", "node", "django", "rails"]
Union with non-existing set
await redis.sadd("set1", "a", "b", "c");
const result = await redis.sunion("set1", "nonexistent");
console.log(result); // ["a", "b", "c"]