Intersecting redis sets that are incomplete

Viewed 119

I have some data that I want to store in redis to be able to efficiently intersect it. Example data:

 key |  members
---------------------------------
 101 |  "a1", "a2", "a3"
 102 |  "a2", "a3"
 103 |  "a2", "a4"

So, the intersection of those keys would give me

SINTER 101 102 103
1) "a2"

However, I have some problems when the dataset is incomplete:

 key |  members
---------------------------------
 101 |  "a1", "a2", "a3"
 102 |  "a2", "a3"
 103 |  "a4", "a5"

In this case, getting an intersection of the same three keys would give me an empty set:

SINTER 101 102 103
(empty list or set)

My goal is to get the member that matches most sets. Is there a way in redis to achieve this? I could alter the way my datasets are stored, if that helps. I.e. creating inverse versions of the sets (members as keys, keys as members)

Also, would it perhaps make sense to use some other key store than redis, which might be more suitable to this task?

1 Answers
Related