Redis: find items active on a given date

Viewed 97

I have a bunch of objects with start and end dates like so:

{id: "1", start_date: "2020-01-01", end_date: "2020-01-15"}
{id: "2", start_date: "2020-01-15", end_date: "2020-01-30"}
{id: "3", start_date: "2020-01-07", end_date: "2020-02-01"}
{id: "4", start_date: "2020-02-01", end_date: "2020-02-15"}

What I need to do is find the objects that are active on a given date. For example, given the date "2020-01-10", it should return objects 1 and 3 since their start_date is <= to 2020-01-10 and their end_date is >= 2020-01-10.

What is the proper Redis data structure to be able to perform this type of lookup? Sorted sets seem like the right choice, but I can't wrap my head around how to perform this sort of lookup with sorted sets.

0 Answers
Related