Skip to main content
Returns the members of the set resulting from the intersection of all the given sets. Keys that do not exist are considered to be empty sets.

Usage

await redis.sinter(key, ...keys);

Parameters

key
string
required
The first set key
keys
string[]
Additional set keys to intersect with

Response

result
TData[]
An array containing the members of the resulting set (intersection of all sets)

Examples

Intersect two sets

await redis.sadd("set1", "a", "b", "c", "d");
await redis.sadd("set2", "c", "d", "e", "f");

const result = await redis.sinter("set1", "set2");
console.log(result); // ["c", "d"]

Intersect multiple sets

await redis.sadd("tags:post1", "javascript", "typescript", "react");
await redis.sadd("tags:post2", "typescript", "react", "node");
await redis.sadd("tags:post3", "react", "vue", "typescript");

const commonTags = await redis.sinter("tags:post1", "tags:post2", "tags:post3");
console.log(commonTags); // ["typescript", "react"]

Find common friends

await redis.sadd("friends:alice", "bob", "charlie", "david");
await redis.sadd("friends:bob", "alice", "charlie", "eve");

const mutualFriends = await redis.sinter("friends:alice", "friends:bob");
console.log(mutualFriends); // ["charlie"]

Empty intersection

await redis.sadd("set1", "a", "b", "c");
await redis.sadd("set2", "d", "e", "f");

const result = await redis.sinter("set1", "set2");
console.log(result); // []

Build docs developers (and LLMs) love