I have a MySQL table "number_records" with more than 10 million entries. The table has following structure.
id | number | cat_id | dialed | uuid |
1 | 2123727345 | 148 | 0 | |
2 | 2123727346 | 148 | 0 | |
3 | 212372737 | 147 | 0 | |
I have two processes having same cat_id(148) but different UUID concurrently using above table to get numbers.
First Process uuid = abcd-efgh-12345-78908
Second Process uuid = zxcv-qwrt-uuuu-kklll
I want that each process gets only a unique number and after processing set its dialed status to '1'. (Both processes do not get the same number)
I am doing above in three queries in each process so that each process gets only one unique number.
For the first process.
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;
For the Second process.
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'
This process is working fine. And above queries make sure that I get one unique number per process.
But table contains more than 10 million records. And these queries takes more than 5 seconds. I want to speed up the process.
My manager asked me to shift above table to Redis.And I am confused how to shift above table.
How could I use Redis in above case?
Any suggestion is much appreciated. Best Regards.