where("votes", ">", 100)->sharedLo" />
牛骨文教育服务平台(让学习变的简单)

悲观锁定 (Pessimistic Locking)

查询构造器提供了少数函数协助你在 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();