PECL Redis Support

Started by Steel87, October 22, 2016, 10:04:59 PM

Previous topic - Next topic

Steel87

Link to Mod

This mod adds support for using a Redis Server as caching backend. For functioning the PECL redis extension is needed.

Adz.

Great mod! I have redis installed on my server and i think redis is much better. Since neither smf 2.0 nor 2.1 support it. Do we need any manual configuring?

Cheers.

@rjen

It seems this Mod is not ued very often .
:-\

My hosting partner is suggesting to use Redis caching. I want to give it a a try, but it seems there is a difference in settings.

Hosting partner states I only need to to Unix-socket: /tmp/redis.sock
This MOD requires to specifiy "Redis Server and Port (e.g. localhost:6379)"

Does anyone know what setting to use?

I tried entering the value /tmp/redis.sock but that does not work ...
Running SMF 2.1 with latest TinyPortal at www.fjr-club.nl

tinoest

Either you need to move the socket to another location; https://serverfault.com/questions/463993/nginx-unix-domain-socket-error/464025#464025

Or you need to replace the following function with the below, which removes the port setting on the connect string.


function get_redis_server()
{
global $modSettings, $redisServer, $redisServer_connected;

if(!isset($redisServer_connected)) {
$redisServer = new Redis;
$redisServer_connected = false;

$servers = explode(',', $modSettings['cache_redis']);
$connectServer = array();
foreach ($servers as $server_){
$server = explode(':', $server_);

$server[1] = empty($server[1]) ? 6379 : $server[1];

if(!empty($server[0])) {
$connectServer[] = $server;
if($redisServer->connect($server[0]) {
$redisServer_connected = true;

if(!empty($modSettings['cache_redis_password']))
$redisServer_connected = $redisServer->auth($modSettings['cache_redis_password']);
}
}
}

if (!$redisServer_connected) {
$redisServer = false;
} else {
$redisServer->select(max(0, (int) $modSettings['cache_redis_db']));
}
}

return $redisServer;
}

@rjen

Thanks,

forgot to update here, but I already got it working by simply removing the port default the MOD is setting...

This line was  setting the port default. I commented it out...
      $server[1] = empty($server[1]) ? 6379 : $server[1];


function get_redis_server()
{
global $modSettings, $redisServer, $redisServer_connected;

if(!isset($redisServer_connected)) {
$redisServer = new Redis;
$redisServer_connected = false;

$servers = explode(',', $modSettings['cache_redis']);
$connectServer = array();
foreach ($servers as $server_){
$server = explode(':', $server_);

/* $server[1] = empty($server[1]) ? 6379 : $server[1];*/

if(!empty($server[0])) {
$connectServer[] = $server;
if($redisServer->connect($server[0], $server[1])) {
$redisServer_connected = true;

if(!empty($modSettings['cache_redis_password']))
$redisServer_connected = $redisServer->auth($modSettings['cache_redis_password']);
}
}
}

if (!$redisServer_connected) {
$redisServer = false;
} else {
$redisServer->select(max(0, (int) $modSettings['cache_redis_db']));
}
}

return $redisServer;
}
Running SMF 2.1 with latest TinyPortal at www.fjr-club.nl

@rjen

Quote from: tinoest on March 22, 2020, 10:43:28 AM
Either you need to move the socket to another location; https://serverfault.com/questions/463993/nginx-unix-domain-socket-error/464025#464025

Or you need to replace the following function with the below, which removes the port setting on the connect string.


I just applied your code, since I was getting undefined index errors with min. Seems you missed one ') '..

Correct code below:


function get_redis_server()
{
global $modSettings, $redisServer, $redisServer_connected;

if(!isset($redisServer_connected)) {
$redisServer = new Redis;
$redisServer_connected = false;

$servers = explode(',', $modSettings['cache_redis']);
$connectServer = array();
foreach ($servers as $server_){
$server = explode(':', $server_);

$server[1] = empty($server[1]) ? 6379 : $server[1];

if(!empty($server[0])) {
$connectServer[] = $server;
if($redisServer->connect($server[0]) {
$redisServer_connected = true;

if(!empty($modSettings['cache_redis_password']))
$redisServer_connected = $redisServer->auth($modSettings['cache_redis_password']);
}
}
}

if (!$redisServer_connected) {
$redisServer = false;
} else {
$redisServer->select(max(0, (int) $modSettings['cache_redis_db']));
}
}

return $redisServer;
}


By the way leaving the database number empty also results in undefined index errors: default database is '0'. Setting the database to 1 solves that too..

Running SMF 2.1 with latest TinyPortal at www.fjr-club.nl

Advertisement: