1

Am I right to think that Redis should be configured with a TCP port to work with CiviCRM?

I would like to use the Unix socket option.

2
  • What happened when you tried it? I haven't tried but it looks like you could just set define('CIVICRM_DB_CACHE_HOST', '/tmp/redis.sock'); in civicrm.settings.php (adjust file path as needed).
    – Demerit
    Nov 5, 2020 at 13:41
  • Defining CIVICRM_DB_CACHE_HOST as a socket does not work: Redis::connect(): php_network_getaddresses: getaddrinfo for /run/redis/redis.sock failed: Name or service not known Redis.php:70 Nov 29, 2023 at 15:37

1 Answer 1

0

You can replace the connect function in /vendor/civicrm/civicrm-core/CRM/Utils/Cache/Redis.php to use pconnect to connect via a socket:

public static function connect($config) {
    $socket = '/run/redis/redis.sock'; // Path to the Redis socket
    $pass = CRM_Utils_Constant::value('CIVICRM_DB_CACHE_PASSWORD');
    $id = implode(':', ['connect', $socket /* $pass is constant */]);
    if (!isset(Civi::$statics[__CLASS__][$id])) {
        $redis = new Redis();
        if (!$redis->pconnect($socket)) {
            // dont use fatal here since we can go in an infinite loop
            echo 'Could not connect to Redis server using socket';
            CRM_Utils_System::civiExit();
        }
        if ($pass) {
            $redis->auth($pass);
        }
        Civi::$statics[__CLASS__][$id] = $redis;
    }
    return Civi::$statics[__CLASS__][$id];
  }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.