【发布时间】:2026-02-04 10:50:01
【问题描述】:
我有一个包含超过 1000 万条条目的 MySQL 表“number_records”。该表具有以下结构。
id | number | cat_id | dialed | uuid |
1 | 2123727345 | 148 | 0 | |
2 | 2123727346 | 148 | 0 | |
3 | 212372737 | 147 | 0 | |
我有两个具有相同 cat_id(148) 但不同 UUID 的进程同时使用上表获取数字。
第一个进程 uuid = abcd-efgh-12345-78908
第二道工序 uuid = zxcv-qwrt-uuuu-kklll
我希望每个进程只获得一个唯一的号码,并在处理后将其拨号状态设置为“1”。 (两个进程得到的编号不同)
我在每个进程的三个查询中执行上述操作,以便每个进程仅获得一个唯一编号。
对于第一个过程。
update numbers_records set uuid = 'abcd-efgh-12345-78908' where cat_id = 148 and dialed = 0 and uuid = "";select number from numbers_records where uuid = 'abcd-efgh-12345-78908' and dialed = 0 and cat_id = 148;update numbers_records set dialed = 1 where uuid ='abcd-efgh-12345-78908' and cat_id = 148 and dialed = 0;
对于第二个过程。
update numbers_records set uuid = 'zxcv-qwrt-uuuu-kklll' where cat_id = 148 and dialed = 0 and uuid = "";select number from numbers_records where uuid = 'zxcv-qwrt-uuuu-kklll' and dialed = 0;update numbers_records set dialed = 1 where uuid = 'zxcv-qwrt-uuuu-kklll'
此过程运行良好。上面的查询确保我得到每个进程一个唯一的数字。
但表包含超过 1000 万条记录。而这些查询耗时超过 5 秒。我想加快这个过程。
我的经理让我将上表转移到 Redis。我很困惑如何在表上转移。
在上述情况下如何使用 Redis?
非常感谢任何建议。 最好的祝福。
【问题讨论】: