Skip to content

Conversation

@AlikDex
Copy link

@AlikDex AlikDex commented Dec 23, 2019

Q A
Is bugfix? no
New feature? no
Breaks BC? no
Tests pass? yes
Fixed issues #195
@samdark samdark added this to the 2.0.12 milestone Dec 23, 2019
Copy link
Member

@samdark samdark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a line to changelog describing the change

@samdark samdark added the status:ready for merge The pull request is OK to be merged. label Dec 23, 2019
@samdark samdark requested a review from a team December 23, 2019 15:52
public static function getDb()
{
return Yii::$app->get('redis');
return Instance::ensure('redis', Connection::className());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may break BC and it is inconsistent with yii\db\ActiverRecord which always point to Yii::$app->db (https://github.com/yiisoft/yii2/blob/b79fe7d106b8f901d3f3f2fd01eae811ce2c34ec/framework/db/ActiveRecord.php#L135). You should override this method in your model if you want to use different approach.

{
if (is_string($this->redis)) {
$this->redis = Yii::$app->get($this->redis);
$this->redis = Instance::ensure($this->redis, Connection::className());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could replace entire initialization of $redis property by Instance::ensure().

if (is_string($this->redis)) {
$this->redis = Instance::ensure($this->redis, Connection::className());
} elseif (is_array($this->redis)) {
if (!isset($this->redis['class'])) {
$this->redis['class'] = Connection::className();
}
$this->redis = Yii::createObject($this->redis);
}
if (!$this->redis instanceof Connection) {
throw new InvalidConfigException("Session::redis must be either a Redis connection instance or the application component ID of a Redis connection.");
}

@samdark
Copy link
Member

samdark commented Feb 22, 2020

@AlikDex, @rob006 is there a way to fix it in a backwards compatible manner?

@rob006
Copy link
Contributor

rob006 commented Feb 22, 2020

IMO changes in ActiveRecord are unnecessary. This how it works for other AR implementations - if you want different component/approach to be used for connection, you should override getDb() in your model. Changing this will only create inconsistency.

@samdark
Copy link
Member

samdark commented Feb 22, 2020

Yes. Agree.

@samdark samdark closed this Feb 22, 2020
@rob006
Copy link
Contributor

rob006 commented Feb 22, 2020

@samdark It is still worth to simplify Session::init() by using Instance::ensure() for initialization of redis property. It will be more consistent, simplify implementation and make configuration more flexible.

@samdark
Copy link
Member

samdark commented Feb 22, 2020

@rob006 since you're on it, how about a pull request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status:ready for merge The pull request is OK to be merged.

3 participants