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
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.
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
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.