From 465e4b32ee81d014d770775fe37eb78254f1dc67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20H=C3=A4rdeman?= Date: Sat, 21 Aug 2021 13:32:17 +0200 Subject: [PATCH 1/2] [snappymail] Improve Redis support By using a connection URL, it is possible to support all Predis features, like passwords, unix sockets, database selection, etc. Tested with TCP and unix socket connections. Closes #113 --- .../libraries/MailSo/Cache/Drivers/Redis.php | 17 ++++------------- .../v/0.0.0/app/libraries/RainLoop/Actions.php | 3 +-- .../libraries/RainLoop/Config/Application.php | 3 +-- 3 files changed, 6 insertions(+), 17 deletions(-) diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Cache/Drivers/Redis.php b/snappymail/v/0.0.0/app/libraries/MailSo/Cache/Drivers/Redis.php index aa277ebf7..bd2f5a2e2 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Cache/Drivers/Redis.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Cache/Drivers/Redis.php @@ -21,12 +21,7 @@ class Redis implements \MailSo\Cache\DriverInterface /** * @var string */ - private $sHost; - - /** - * @var int - */ - private $iPost; + private $sUrl; /** * @var int @@ -43,20 +38,16 @@ class Redis implements \MailSo\Cache\DriverInterface */ private $sKeyPrefix; - function __construct(string $sHost = '127.0.0.1', int $iPost = 6379, int $iExpire = 43200, string $sKeyPrefix = '') + function __construct(string $sUrl = 'redis://127.0.0.1:6379', int $iExpire = 43200, string $sKeyPrefix = '') { - $this->sHost = $sHost; - $this->iPost = $iPost; + $this->sUrl = $sUrl; $this->iExpire = 0 < $iExpire ? $iExpire : 43200; $this->oRedis = null; try { - $this->oRedis = new \Predis\Client('unix:' === substr($sHost, 0, 5) ? $sHost : array( - 'host' => $sHost, - 'port' => $iPost - )); + $this->oRedis = new \Predis\Client($sUrl); $this->oRedis->connect(); diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php index 0c49038b8..3c25be6d3 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php @@ -706,8 +706,7 @@ class Actions case 'REDIS' === $sDriver && \class_exists('Predis\Client'): $oDriver = new \MailSo\Cache\Drivers\Redis( - $this->Config()->Get('labs', 'fast_cache_redis_host', '127.0.0.1'), - (int)$this->Config()->Get('labs', 'fast_cache_redis_port', 6379), + $this->Config()->Get('labs', 'fast_cache_redis_url', 'redis://127.0.0.1:6379'), 43200, $sKey ); diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Config/Application.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Config/Application.php index df3f2fe63..2106856ce 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Config/Application.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Config/Application.php @@ -367,8 +367,7 @@ Enables caching in the system'), 'http_client_ip_check_proxy' => array(false), 'fast_cache_memcache_host' => array('127.0.0.1'), 'fast_cache_memcache_port' => array(11211), - 'fast_cache_redis_host' => array('127.0.0.1'), - 'fast_cache_redis_port' => array(6379), + 'fast_cache_redis_url' => array('redis://127.0.0.1:6379'), 'use_local_proxy_for_external_images' => array(true), 'detect_image_exif_orientation' => array(true), 'cookie_default_path' => array(''), From bd6b903b74db5cd071a2fc8aff2cde72557853f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20H=C3=A4rdeman?= Date: Sat, 21 Aug 2021 14:06:30 +0200 Subject: [PATCH 2/2] [snappymail] Change default connection string for Redis The "redis" scheme is undocumented and has a slightly different syntax, so prefer the "tcp" scheme. --- snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php | 2 +- .../v/0.0.0/app/libraries/RainLoop/Config/Application.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php index 3c25be6d3..c6cec8b8a 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php @@ -706,7 +706,7 @@ class Actions case 'REDIS' === $sDriver && \class_exists('Predis\Client'): $oDriver = new \MailSo\Cache\Drivers\Redis( - $this->Config()->Get('labs', 'fast_cache_redis_url', 'redis://127.0.0.1:6379'), + $this->Config()->Get('labs', 'fast_cache_redis_url', 'tcp://127.0.0.1:6379'), 43200, $sKey ); diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Config/Application.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Config/Application.php index 2106856ce..4255b7893 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Config/Application.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Config/Application.php @@ -367,7 +367,7 @@ Enables caching in the system'), 'http_client_ip_check_proxy' => array(false), 'fast_cache_memcache_host' => array('127.0.0.1'), 'fast_cache_memcache_port' => array(11211), - 'fast_cache_redis_url' => array('redis://127.0.0.1:6379'), + 'fast_cache_redis_url' => array('tcp://127.0.0.1:6379'), 'use_local_proxy_for_external_images' => array(true), 'detect_image_exif_orientation' => array(true), 'cookie_default_path' => array(''),