Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Yii Framework 2 redis extension Change Log
2.0.12 under development
------------------------

- no changes in this release.
- Enh #195: Use `Instance::ensure()` to initialize `Session::$redis` (rob006)


2.0.11 November 05, 2019
Expand Down
13 changes: 2 additions & 11 deletions src/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use Yii;
use yii\base\InvalidConfigException;
use yii\di\Instance;

/**
* Redis Session implements a session component using [redis](http://redis.io/) as the storage medium.
Expand Down Expand Up @@ -79,17 +80,7 @@ class Session extends \yii\web\Session
*/
public function init()
{
if (is_string($this->redis)) {
$this->redis = Yii::$app->get($this->redis);
} 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.");
}
$this->redis = Instance::ensure($this->redis, Connection::className());
if ($this->keyPrefix === null) {
$this->keyPrefix = substr(md5(Yii::$app->id), 0, 5);
}
Expand Down