Answers.Body: <p>You can replace the connect function in /vendor/civicrm/civicrm-core/CRM/Utils/Cache/Redis.php to use pconnect to connect via a socket:</p>
  <pre><code>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-&gt;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-&gt;auth($pass);
          }
          Civi::$statics[__CLASS__][$id] = $redis;
      }
      return Civi::$statics[__CLASS__][$id];
    }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-11-29T15:39:12.227Z
Answers.LastActivityDate: 2023-11-29T15:39:12.227Z
Answers.UserDisplayName: Hans Rossel
Body: <p>Am I right to think that Redis should be configured with a TCP port to work with CiviCRM?</p>
  <p>I would like to use the Unix socket option.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-11-05T13:41:05.277Z
Comments.Text: 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).
Comments.UserDisplayName: Demerit
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-11-29T15:37:02.173Z
Comments.Text: 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
Comments.UserDisplayName: Hans Rossel
Tags: <cache>
Title: Redis running on socket?
ThreadText: # Redis running on socket?
  
  (Asked by: username_0 on 2020-11-04)
  
  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.
  
  **Tags:** cache
  
  > **Comments:**
  > **username_1**: 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).  
  > **username_2**: 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  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2023-11-29. Score: 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];
    }
  
  
  ---
  
  