XenForo + Redis + Glue code
This "addon" is the required gluecode to use Cm_Cache_Backend_Redis to provide a Zend Cache target for Redis.
Additionally, this addon implement caching of thread counts in a forum.
To prevent double encoding of cached data, it is strongly recommended to have the following configuration in XenForo's config.php:
$config['cache']['frontendOptions']['automatic_serialization'] = false;
Warning You must manually flush the cache after changing this setting!
Optionally, (pipelining or loading from a slave can be enabled in XenForo_Model_DataRegistry::getMulti by adding the following lines to config.php. Preferably after setting up the cache.
require(XenForo_Application::getInstance()->getConfigDir().'/SV/RedisCache/Installer.php');
For best performance use: phpredis PECL extension
$config['cache']['enabled'] = true;
$config['cache']['frontend'] = 'Core';
$config['cache']['frontendOptions']['cache_id_prefix'] = 'xf_';
$config['cache']['backend'] = 'Redis';
$config['cache']['backendOptions'] = array(
'server' => '127.0.0.1',
'port' => 6379,
'connect_retries' => 2,
'use_lua' => true,
'compress_data' => 2,
'read_timeout' => 1,
'timeout' => 1,
);
Loading Data from a single slave is possible, or alternatively Redis Sentinel support can be used high-availability. See http://redis.io/topics/sentinel for more information.
$config['cache']['backendOptions']['load_from_slave'] = array(
'server' => '127.0.0.1',
'port' => 6378,
'connect_retries' => 2,
'use_lua' => true,
'compress_data' => 2,
'read_timeout' => 1,
'timeout' => 1,
'retry_reads_on_master' => true,
);
If 'retry_reads_on_master' is truthy then reads will be retried against master when slave returns "(nil)" value (ie slave is not yet initialized).
$config['cache']['backendOptions']['sentinel_master'] = 'mymaster';
$config['cache']['backendOptions']['server'] = '127.0.0.1:26379';
'server' now points to a comma delimited list of sentinal servers to find the master. Note; the port must be explicitly listed
To load data from slaves use;
$config['cache']['backendOptions']['load_from_slaves'] = true;
This will prefer any slave with an IP matching an IP on the machine. This is fetched via the non-portable method:shell_exec("hostname --all-ip-addresses")
To run on windows, or if shell_exec is disabled, you must define an 'slave-select' attribute.
By default, a local slave is preferred, this can be changed by setting:
$config['cache']['backendOptions']['slave_select_callable'] = function (array $slaves) {
$slaveKey = array_rand($slaves, 1);
return $slaves[$slaveKey];
};
Setting to false (or some non-callable) will fall back to a random slave.
By default the Zend Cache "tags" support is disabled as XenForo does not use it and it introduces additional operations to support it. To enable;
$config['cache']['backendOptions']['enable_tags'] = true;
Licensing:
New BSD License:
- Cm_Cache_Backend_Redis
- Credis
MIT Licensed:
- XenForo Addon code