參考網址:https://www.sunzhongwei.com/using-laravel-sharedlock-and-lockforupdate-for-table-row-locks
個人覺得這種場景下並發數量比商品秒殺小得多,一個團的拼團入口由用戶的朋友圈有關,可以使用數據庫行鎖控制。
sharedLock 與 lockForUpdate 相同的地方是,都能避免同一行數據被其他 transaction 進行 update。
不同的地方是:
- sharedLock 不會阻止其他 transaction 讀取同一行
- lockForUpdate 會阻止其他 transaction 讀取同一行 (需要特別注意的是,普通的非鎖定讀取讀取依然可以讀取到該行,只有 sharedLock 和 lockForUpdate 的讀取會被阻止。)