请教关于 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
判断条件被修改了.
感谢回复
推荐文章: