Caching 在Redis中,基于对象的两个属性进行查询时,正确的数据结构是什么

Caching 在Redis中,基于对象的两个属性进行查询时,正确的数据结构是什么,caching,data-structures,redis,Caching,Data Structures,Redis,我是Redis的新手,希望从专家那里得到关于我的用例的建议。我有一个事件对象,它有两个属性:事件的开始时间和事件的结束时间(对象中还有很多属性)。我有数百万个这样的事件,需要将它们存储在Redis中,以便在运行时查询它们。我希望使用时间戳作为键,使用事件对象作为值。在查询时,我需要获取事件列表,其中从现在开始的一周内,事件的开始时间为。不确定Redis中的ZRANGE、LRANGE或任何其他数据结构是否支持使用多个(复杂)键。关于使用Redis实现上述用例的最佳方式有什么建议 提前非常感谢。您应

我是Redis的新手,希望从专家那里得到关于我的用例的建议。我有一个事件对象,它有两个属性:事件的开始时间和事件的结束时间(对象中还有很多属性)。我有数百万个这样的事件,需要将它们存储在Redis中,以便在运行时查询它们。我希望使用时间戳作为键,使用事件对象作为值。在查询时,我需要获取事件列表,其中从现在开始的一周内,事件的开始时间为。不确定Redis中的ZRANGE、LRANGE或任何其他数据结构是否支持使用多个(复杂)键。关于使用Redis实现上述用例的最佳方式有什么建议


提前非常感谢。

您应该将事件存储在两个Redis Z集中,因为一组分数应该是事件的开始时间,另一组分数应该是事件的结束时间

让我们分别称它们为
start\u events
end\u events

加:

搜寻

-- randomly generate a destination id, search the events 
-- and store in that based on the start time

ZRANGESTORE random-start-time-dst start_events 0 current_time

-- randomly generate a destination id for end-time search, post filter 
-- store results in that destination

ZRANGESTORE random-end-time-dst end_events current_time+7.weeks -1

-- Take the intersection of these two sets
ZINTER INT_MAX random-start-time-dst random-end-time-dst 

-- Delete the newly created collections to  free up the memory 
DEL random-start-time-dst
DEL random-end-time-dst

另一种选择是将这些信息存储在辅助索引(SQL表)中

一旦这些数据位于表中,就可以使用标准SQL查询它们


这将只是一个简单的SQL查询,不需要维护Redis结构。

谢谢@sonus21。您的回答非常有用。有关如何操作的详细信息,请参阅:
-- randomly generate a destination id, search the events 
-- and store in that based on the start time

ZRANGESTORE random-start-time-dst start_events 0 current_time

-- randomly generate a destination id for end-time search, post filter 
-- store results in that destination

ZRANGESTORE random-end-time-dst end_events current_time+7.weeks -1

-- Take the intersection of these two sets
ZINTER INT_MAX random-start-time-dst random-end-time-dst 

-- Delete the newly created collections to  free up the memory 
DEL random-start-time-dst
DEL random-end-time-dst