I am designing a backend that matches users randomly based on preferences.
There are four different types of preferences.
- All - Can match with any user
- Seven - Can only match with either "All" or "Seven"
- Eight - Can only match with either "All" or "Eight"
- Nine - Can only match with either "All" or "Nine".
I currently use the REDIS list data type to store users in a queue and match them.
My approach:
I am creating 4 lists for the preferences and then looking up each list and matching the users as per their needs.
queue:all
queue:seven
queue:eight
queue:nine
if user.pref == all
search - all
search - seven
search - eight
search - nine
if user.pref != all
search - all
search - pref
if queue is empty
queue:${pref}.push(user)
The Problem:
The above approach looks pretty inefficient as I have to do multiple lookups for every user.
Is there a better way to do it? So that all of this can be done with a single lookup?