请教关于 sharedLock 和 lockForUpdate 的区别

version:laravel 5.6
路径:Illuminate\Database\Query\Builder

 /**
     * Lock the selected rows in the table.
     *
     * @param  string|bool  $value
     * @return $this
     */
    public function lock($value = true)
    {
        $this->lock = $value;

        if (! is_null($this->lock)) {
            $this->useWritePdo();
        }

        return $this;
    }

    /**
     * Lock the selected rows in the table for updating.
     *
     * @return \Illuminate\Database\Query\Builder
     */
    public function lockForUpdate()
    {
        return $this->lock(true);
    }

    /**
     * Share lock the selected rows in the table.
     *
     * @return \Illuminate\Database\Query\Builder
     */
    public function sharedLock()
    {
        return $this->lock(false);
    }

请问lockForUpdate 和 sharedLock的区别?
function lock里使用了is_null($this->lock)做判断的,都会运行$this->useWritePdo()
laravel 5.3(含)前使用的是

 public function lock($value = true)
    {
        $this->lock = $value;

        if ($this->lock) {
            $this->useWritePdo();
        }

        return $this;
    }

由于这个Issue$this->useWritePdo()的if判断条件被修改了.
感谢回复

《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
讨论数量: 2

lockForUpdate 比 sharedLock 严格。

sharedLock,分享锁。别的事务可以读,但不能写,只能 sharedLock 更新完再写。

lockForUpdate,更新锁。其他的都不能读写,只能 lockForUpdate 更新完再读写。

没用过,只是根据已有的阅读知识的理解。

4年前 评论
No_Panic

file
两者的区别在于:当两个transaction(事务)都在运行.

如果先运行的使用了LockForUpdate,后者在前一个transaction commit前无法选中同一条数据(要等前者跑完).

如果先运行的使用了sharedLock,后运行的即使在commit前也可以选中数据

4年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!