Yii源码解析之DbMutex

版权声明:转载请注明来源 https://blog.csdn.net/u013702678/article/details/84261173

Yii提供了基于DB的加锁机制,其基类为DbMutex。

其源码如下:

abstract class DbMutex extends Mutex
{
    /**
     * @var Connection|array|string the DB connection object or the application component ID of the DB connection.
     * After the Mutex object is created, if you want to change this property, you should only assign
     * it with a DB connection object.
     * Starting from version 2.0.2, this can also be a configuration array for creating the object.
     */
    public $db = 'db';//按注释,需要传入已经创建的db实例对象或者DB连接的对象


    /**
     * Initializes generic database table based mutex implementation.
     * @throws InvalidConfigException if [[db]] is invalid.
     */
    public function init()
    {
        parent::init();
        $this->db = Instance::ensure($this->db, Connection::className());//DB实例初始化
    }
}

猜你喜欢

转载自blog.csdn.net/u013702678/article/details/84261173
今日推荐