How to integrate Redis into Craft CMS version 2
Knowledgebase Article
}
Knowledgebase Article
There are 3 steps you'll need to take in order to make Craft CMS to work properly with Redis that runs as a UNIX socket (as is the case with most single server implementations we host)
/*** The caching method that Craft should use. Valid values are 'apc', 'db', 'eaccelerator', 'file', 'memcache',
* 'redis', 'wincache', 'xcache', and 'zenddata',
*
* Defaults to 'file'.
*/
'cacheMethod' => 'redis',
Here is an example of rediscache.php you can use:
<?php
return array(
/**
* Hostname to use for connecting to the redis server. Defaults to 'localhost'.
*/
'hostname' => 'unix:///home/USER/.kxcache/redis.sock',
/**
* The port to use for connecting to the redis server. Default port is 6379.
*/
'port' => '0',
/**
* The password to use to authenticate with the redis server. If not set, no AUTH command will be sent. LEAVE EMPTY IF USING stream_socket_server BELOW
*/
'password' => '',
/**
* The password to use to authenticate with the redis server. If not set, no AUTH command will be sent.
*/
'stream_socket_server' => 'STREAM_CLIENT_PERSISTENT',
/**
* The redis database to use. This is an integer value starting from 0. Defaults to 0.
*/
'database' => 0,
/**
* Timeout to use for connection to redis. If not set the timeout set in php.ini will be used:
* ini_get("default_socket_timeout")
*/
'timeout' => null,
);
IMPORTANT: Replace the hostname with "Your Redis socket address" as per your cPanel and also set unique database ID for this application if you host multiple applications in the same account that use Redis.
To do that, you'll need to change a line of code in: craft/app/framework/caching/CRedisCache.php
Look for:
$this->hostname.':'.$this->port,
around the 85th line and change it to:
$this->hostname,
Save the change and test your Craft CMS.
The application should be properly working now, serving cache from Redis.
For even greater performance, we can strongly recommend integrating LiteSpeed into Craft CMS.
Powered by WHMCompleteSolution