redis与mysql一致性问题
巴扎黑
巴扎黑 2017-04-17 14:48:45
0
4
704

应用在电商购物库存场景
1、用户下单后 redis对库存id做增加(件数)
2、用户付款成功后 redis对库存id做减少(件数),同时减少mysql里的库存

问题是:
流程中出现问题,mysql可以做数据回滚,但redis不可以
除了记录日志分析外,有较好办法可以解决这个问题么

巴扎黑
巴扎黑

reply all(4)
刘奇

Do you mean that MySQL rollback is a transaction rollback?

Since there is a problem with the process, the code should be able to catch the problem and manually roll back redis.
Or wait until the process transaction is established and submitted before modifying redis.

迷茫

It’s still a matter of things.
Don’t treat mysql operations as one thing and redis operations as another thing.
Treat addition, deletion and modification of data as one thing. Whether it is mysql or redis, as long as there is an error in adding or deleting, the transaction will be rolled back. Please use pipeline for redis.

迷茫

Let’s think about it differently. From a product perspective, you should allow redis data to be asynchronous. Even if redis can be persisted, there is a possibility of data loss if the server hangs up before the memory is flushed to the hard disk. You only need to ensure When placing an order, the SKU inventory can be detected from Mysql. Even if he bypasses redis, the final result can be guaranteed to be correct

PHPzhong

Mysql provides the underlying logic guarantee. Redis recommends only caching. The redis data should be synchronized with mysql periodically or when it does not exist.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template