Redis already has: SINTER It would also be useful to have a method which returns a count of the members of the set resulting from the intersection of all the given sets, rather than the members themselves. This would allow correlations such as Cosine Similarity to be evaluated efficiently.

Comment From: jdp

You can already achieve that result with SINTERSTORE and SCARD in a pipeline:

SINTERSTORE result set1 set2 set3 ... setN
SCARD result

Comment From: jcnewell

Yes, but that involves the unnecessary creation and storage of the intersection set so is it efficient? I have to do the calculation for every possible pair in a large number of sets so efficiency is important.

Comment From: refaelos

+1

Comment From: junxy

:+1:

Comment From: itamarhaber

Lua to the rescue:

local i = redis.call('SINTER', unpack(KEYS))
return #i

This is a variadic script that accepts as input the key names of the sets

Comment From: kurtbartholomew

Looks like this was opened 4 years ago with no response from OP after proposed answer. Can this be closed @itamarhaber ?

Comment From: itamarhaber

@kurtbartholomew I believe so - either OP or the maintainers should do that.

Comment From: itamarhaber

Closing - feel free to reopen or create a new issue if needed.