In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "the index table of the sub-database sub-table of the order system realized by redis". In the daily operation, I believe that many people have doubts about the index table of the sub-database sub-table of the order system realized by redis. The editor has consulted all kinds of data and sorted out a simple and easy-to-use operation method. I hope it will be helpful for everyone to answer the doubt that "redis realizes the sub-database sub-table of the order system". Next, please follow the editor to study!
When sub-database and sub-table, there is still the need for multi-dimensional query, at this time, the common way is to do index table, index table can be implemented in a variety of ways, you can use redis, you can use mysql binlog to achieve, etc., when using redis to achieve index table, how do we design? What are the main points we need? For example, we use district sub-table to set up the merchant's index table and the passenger's index table respectively.
What are our query requirements?
Using redis as an index table, what data structure should we use? How to design it?
How to ensure the consistency between the index table and the main database?
What do we need?
Query requirements are mainly from the order id, from the merchant id, from the buyer id demand, at the same time, there is also query merchant history order, query buyer history order. Then, our national order, by default, if according to the regional table, where the merchant id and buyer id are mapped to the order id and region? At the same time, historical orders involve the time dimension, how to design the index data structure?
How to use redis as an index table?
If you use redis to meet the above indexing requirements? Here zset is very suitable.
New order zadd salerId timestamp OrderId+district;zadd buyerId timestamp OrderId+district; query merchant historical order zrange salerId timestamp1 timestamp2select * from table where order_id = xxx; query buyer historical order zrange buyerId timestamp1 timestamp2select * from table where order_id = xxx; index table how to ensure the consistency with the main database?
The index table needs to be strongly consistent with the main library order table. Here are a few problems. When writing, do you want to write redis or mysql first? redis didn't read it when you read it, but what if mysql changed it? In fact, it is easier to deal with, write first write redis, read when you can not read directly back. Strong consistency requires regular reconciliation between redis and mysql, and then redis needs permission verification and key audit in order to prevent misoperation by developers. It needs to filter key in the codis layer to filter out flush and other instructions.
To sum up, using redis to do the secondary index of mysql is actually a feasible scheme, and there have been some practices in some large companies. What are the drawbacks of using redis as an index table? After all, redis is a memory structure, and index refactoring is disgusting if data loss occurs.
At this point, on the "redis order system sub-library sub-table index table" study is over, I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.