【发布时间】:2023-03-20 23:42:01
【问题描述】:
我有一个这样的数据模型:
字段:
- 柜台号码(例如 00888、00777、00123 等)
- 计数器代码(例如 XA、XD、ZA、SI 等)
- 开始日期(例如 2017-12-31 ...)
- 结束日期(例如 2017-12-31 ...)
- 其他柜台日期(例如 xxxxx)
当前的数据结构组织是这样的(根和多子格式):
counter_num + counter_code
---> start_date + end_date --> xxxxxxxx
---> start_date + end_date --> xxxxxxxx
---> start_date + end_date --> xxxxxxxx
例子:
00888 + XA
---> Jan 10 + Jan 20 --> xxxxxxxx
---> Jan 21 + Jan 31 --> xxxxxxxx
---> Feb 01 + Dec 31 --> xxxxxxxx
00888 + ZI
---> Jan 09 + Feb 24 --> xxxxxxxx
---> Feb 25 + Dec 31 --> xxxxxxxx
00777 + XA
---> Jan 09 + Feb 24 --> xxxxxxxx
---> Feb 25 + Dec 31 --> xxxxxxxx
今天检索以两种方式发生:
//Fetch unique counter data using all the composite keys
counter_number + counter_code + date (start_date <= date <= end_date)
//Fetch all the counter codes and corresponding data matching the below conditions
counter_number + date (start_date <= date <= end_date)
在 redis 中对此进行建模的最佳方法是什么,因为我需要缓存一些经常命中的数据。我觉得排序集应该以某种方式做到这一点,但无法对其建模。
更新:
只是为了消除混淆,这里的询问不是针对 SQL“BETWEEN”之类的查询。 '因为我不知道 start_date 和 end_date 值是什么。认为它们只是列名。
我不想要的是
SELECT * FROM redis_db
WHERE counter_num AND
date_value BETWEEN start_date AND end_date
我想要的是
SELECT * FROM redis_db
WHERE counter_num AND
start_date <= specifc_date AND end_date >= specific_date
注意:要求非常接近 Redis 多维索引文档中提出的二维索引
https://redis.io/topics/indexes#multi-dimensional-indexes
我理解了这个概念,但无法消化给出的实现细节。
【问题讨论】:
-
澄清一下,您是否尝试在日期字段中使用动态查询,例如“获取位于 DATE1 和 DATE2 之间的
00888 + XA的所有值”,其中日期可能会有所不同? -
没有。请阅读我对您的回答的评论
标签: redis data-modeling