Skip to content

Commit cd83c7c

Browse files
committed
Merge pull request #28 from creocoder/patch-1
Refactored \yii\redis\Cache::init
2 parents d358e58 + 021c997 commit cd83c7c

File tree

1 file changed

+2
-12
lines changed

1 file changed

+2
-12
lines changed

Cache.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
namespace yii\redis;
99

1010
use Yii;
11-
use yii\base\InvalidConfigException;
11+
use yii\di\Instance;
1212

1313
/**
1414
* Redis Cache implements a cache application component based on [redis](http://redis.io/) key-value store.
@@ -76,17 +76,7 @@ class Cache extends \yii\caching\Cache
7676
public function init()
7777
{
7878
parent::init();
79-
if (is_string($this->redis)) {
80-
$this->redis = Yii::$app->get($this->redis);
81-
} elseif (is_array($this->redis)) {
82-
if (!isset($this->redis['class'])) {
83-
$this->redis['class'] = Connection::className();
84-
}
85-
$this->redis = Yii::createObject($this->redis);
86-
}
87-
if (!$this->redis instanceof Connection) {
88-
throw new InvalidConfigException("Cache::redis must be either a Redis connection instance or the application component ID of a Redis connection.");
89-
}
79+
$this->redis = Instance::ensure($this->redis, Connection::className());
9080
}
9181

9282
/**

0 commit comments

Comments
 (0)