Advertisement:

Author Topic: PECL Redis Support  (Read 1928 times)

Offline Steel87

  • Newbie
  • *
  • Posts: 2
PECL Redis Support
« on: October 22, 2016, 10:04:59 PM »
Link to Mod

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

Offline Adz.

  • Semi-Newbie
  • *
  • Posts: 45
  • 2012
    • Ë|FæÙ¸óÉÖNaí)ÿè¦Òrù(CLÞíÛYUø½pïkÁC8¶ÃI]¤ on Facebook
Re: PECL Redis Support
« Reply #1 on: February 01, 2017, 09:38:47 AM »
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.

Online @rjen

  • Full Member
  • ***
  • Posts: 609
  • Gender: Male
    • FJR-club Nederland
Re: PECL Redis Support
« Reply #2 on: March 20, 2020, 01:59:01 PM »
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.0 with Tinyportal 2.0.0 at www.fjr-club.nl
Testing SMF 2.1 with Tinyportal 2.0.0 at test2.fjr-club.nl

Offline tinoest

  • Development Contributor
  • Jr. Member
  • *
  • Posts: 248
Re: PECL Redis Support
« Reply #3 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.

Code: [Select]
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;
}

Online @rjen

  • Full Member
  • ***
  • Posts: 609
  • Gender: Male
    • FJR-club Nederland
Re: PECL Redis Support
« Reply #4 on: March 22, 2020, 12:52:07 PM »
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];

Code: [Select]
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.0 with Tinyportal 2.0.0 at www.fjr-club.nl
Testing SMF 2.1 with Tinyportal 2.0.0 at test2.fjr-club.nl

Online @rjen

  • Full Member
  • ***
  • Posts: 609
  • Gender: Male
    • FJR-club Nederland
Re: PECL Redis Support
« Reply #5 on: March 22, 2020, 04:13:27 PM »
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:

Code: [Select]
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.0 with Tinyportal 2.0.0 at www.fjr-club.nl
Testing SMF 2.1 with Tinyportal 2.0.0 at test2.fjr-club.nl