yiisoft / yii2-redis

Yii 2 Redis extension.
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
452 stars 183 forks source link

Connection::isActive() returns FALSE when the connection is active #215

Closed cornernote closed 3 years ago

cornernote commented 3 years ago

Connection::isActive() returns FALSE when the connection is active. This occurs when using the Connection::useSSL property because "$this->hostname:$this->port" is now different to $this->connectionString because of the tcp:// prefix.

What steps will reproduce the problem?

Yii::$app->redis->ping('hello');
var_dump(Yii::$app->redis->isActive); // returns false, should be true
sleep(60);

In redis-cli, run CLIENT LIST and you will see the connection is still open for 60 seconds.

What's expected?

Yii::$app->redis->isActive should return TRUE when the connection is active.

What do you get instead?

Yii::$app->redis->isActive returns FALSE when the connection is active.

Solution

This line:

        return ArrayHelper::getValue($this->_pool, "$this->hostname:$this->port", false) !== false;

Should be changed to:

        return ArrayHelper::getValue($this->_pool, $this->connectionString, false) !== false;