craftcms / cms

Build bespoke content experiences with Craft.
https://craftcms.com
Other
3.21k stars 624 forks source link

'redis' not actually available as a cache method #1314

Closed ghost closed 7 years ago

ghost commented 7 years ago

Description

In the comments in the config files, it mentions redis as a cache option, but it's coming back as an unsupported cache type.

Missing in https://github.com/craftcms/cms/blob/develop/src/config/components/common.php#L129

Steps to reproduce

  1. Set cache type in configs as "redis"
  2. Get \InvalidArgumentException

Additional info

brandonkelly commented 7 years ago

Turns out Redis support was removed from Yii 2, and moved into a separate extension. It should be possible to Composer-install that extension yourself and make the application config adjustments it requires via config/app.php, so I just updated the cacheMethod comment to not include redis anymore.

rsanchez commented 7 years ago

@brandonkelly FYI, you can't use that Redis Yii extension because Craft validates the cacheMethod here:

// Validate cacheMethod
if (!in_array($this->cacheMethod, [self::CACHE_METHOD_APC, self::CACHE_METHOD_DB, self::CACHE_METHOD_FILE, self::CACHE_METHOD_MEMCACHE, self::CACHE_METHOD_WINCACHE, self::CACHE_METHOD_XCACHE, self::CACHE_METHOD_ZENDDATA], true)) {
    throw new InvalidConfigException('Unsupported cacheMethod value: '.$this->cacheMethod);
}

Any chance of making redis an first-class option again?

brandonkelly commented 7 years ago

There’s no need to change the cacheMethod value. Your config/app.php file will be completely overriding Craft’s cache component definition, which is the only place that checks the cacheMethod setting.

Here’s what your config/app.php might look like:

return [
    'components' => [
        'cache' => [
            'class' => yii\redis\Cache::class,
            'redis' => [
                'hostname' => 'localhost',
                'port' => 6379,
                'database' => 0,
            ],
        ],
    ],
];