yiisoft / yii2-redis

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

Potential problem in 2.0.11 [ERR This instance has cluster support disabled] #192

Closed eridiumdev closed 4 years ago

eridiumdev commented 4 years ago

Foreword

This is not a bug/issue report. This is a heads up for people upgrading to 2.0.11 I am sorry if this does not belong here (feel free to remove)

Problem

If you encounter "ERR This instance has cluster support disabled" Redis Exception, chances are you are, like me, overriding yii\redis\Connection::executeCommand() and NOT using Redis cluster mode.

This happens because 2.0.11 introduced a bunch of fixes for working with Redis in cluster, and one of them is a getIsCluster() check, that calls redis->executeCommand('CLUSTER INFO') internally. Consequentially, this raises forementioned exception, which is ignored in source code, but in case you are overriding executeCommand, you might need to handle it yourself.

Solutions

A. Handle the exception. For instance, "ERR This instance has cluster support disabled" is a yii\db\Exception, so you can differentiate it from e.g. yii\redis\SocketException

B. If you don't intend on working in cluster mode, specify 'forceClusterMode' => false, in your Redis cache component config. This way, exception is never thrown:

'myRedis' => [
    'class' => 'yii\redis\Cache',
    'forceClusterMode' => false,
    'redis' => [
        ...
    ]
],

C. Use Redis in cluster :)
In this case, I think it's preferrable to set 'forceClusterMode' => true

Additional info

Q A
Yii vesion 2.0.30
yii2-redis version 2.0.11
PHP version 7.2.12
Operating system Apline Linux v3.8 @ Docker v19.03.4
samdark commented 4 years ago

It could be added to UPGRADE.md (same as it's done for other extensions). @eridiumdev would you like to prepare a pull request?

eridiumdev commented 4 years ago

Sure, opened one. I guess this issue can be closed as well.