Unbounded multidimensional index using Redis

Viewed 488

I am using Redis in a project where I want to cache "timeitems", ie objects with a start- ("t_start") and endtime ("t_end").

I want to query the cache using a time window that also has a start- ("w_start") and endtime ("w_end). I want to find all timeitems that in overlaps the time window in any way.

I have already successfully implemented this using a sorted set with scores, (using score = t_start + (t_end - t_start) but that only gives me hits where the center of the timeitem is within the time window.

The overlap query in code is simply:

bool overlap = t_start < w_end && w_start < t_end

Now, I have read the documentation about multidimensional indexes here: http://redis.io/topics/indexes#multi-dimensional-indexes

But after banging my head for the better part of today I am starting to think that it wont work in this scenario because the problem is unbounded (?). That is, it it should detect an overlap from a time item that starts before and ends after the time window.

If anyone has worked on a similiar linearization problem, I would love to hear about it.

1 Answers
Related