阅读(3536) (1)

悲观锁定 (Pessimistic Locking)

2016-02-24 15:52:50 更新

查询构造器提供了少数函数协助你在 SELECT 语句中做到「悲观锁定」。

想要在 SELECT 语句中加上「Shard lock」,只要在查找语句中使用 sharedLock 函数:

DB::table('users')->where('votes', '>', 100)->sharedLock()->get();

要在 select 语法中使用「锁住更新(lock for update)」时,你可以使用 lockForUpdate 方法:

DB::table('users')->where('votes', '>', 100)->lockForUpdate()->get();