简体   繁体   English

在Laravel中运行事务时,具有InnoDB的MySQL实例是否锁定行?

[英]Does a MySQL instance with InnoDB lock the rows when I run a transaction in Laravel?

I am trying to implement an in-app credit system using Laravel 4.2. 我正在尝试使用Laravel 4.2实施应用程序内积分系统。 I am planning to store the user credit in a table. 我打算将用户信用存储在一个表中。 As I want an user credit to be free of race conditions, I researched the internet for a proper implementation. 因为我希望用户信用不受种族条件的影响,所以我研究了互联网以寻求适当的实施方式。 Some of the answers were suggesting that if I would use Laravel transactions + MySQL instance with InnoDB there won't be any race conditions. 一些答案表明,如果我将Laravel事务+ MySQL实例与InnoDB一起使用,将不会有任何竞争情况。 Some answers suggested me to use lockForUpdate, but I fear an improper use might lead to deadlock. 一些答案建议我使用lockForUpdate,但我担心使用不当可能会导致死锁。

How should I implement it? 我应该如何实施? Am I safe if I just use transactions? 如果我仅使用交易,是否安全?

I went through the source code and found out that Laravel 4.2's transactions are based on PDO transactions (eg. PDO::beginTransaction). 我遍历了源代码,发现Laravel 4.2的事务基于PDO事务(例如PDO :: beginTransaction)。 Using PDO transactions with MySQL has this kind of behavior. 在MySQL中使用PDO事务具有这种行为。 As the ACID rules are followed, I am assuming that I am safe for my use case. 遵循ACID规则,我假设我对自己的用例是安全的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM