From 8e8feb9d0545780d2a98418626894ea13690db23 Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean Date: Mon, 10 Nov 2025 10:56:08 +0700 Subject: [PATCH 01/11] feat: added async & persistent options to cache predis --- app/Config/Cache.php | 14 ++++++++------ system/Cache/Handlers/PredisHandler.php | 14 +++++++++----- user_guide_src/source/changelogs/v4.7.0.rst | 1 + 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/app/Config/Cache.php b/app/Config/Cache.php index 1169c95ff7ee..0cf34985a4ac 100644 --- a/app/Config/Cache.php +++ b/app/Config/Cache.php @@ -112,14 +112,16 @@ class Cache extends BaseConfig * Your Redis server can be specified below, if you are using * the Redis or Predis drivers. * - * @var array{host?: string, password?: string|null, port?: int, timeout?: int, database?: int} + * @var array{host?: string, password?: string|null, port?: int, timeout?: int, async?: bool, persistent?: bool, database?: int} */ public array $redis = [ - 'host' => '127.0.0.1', - 'password' => null, - 'port' => 6379, - 'timeout' => 0, - 'database' => 0, + 'host' => '127.0.0.1', + 'password' => null, + 'port' => 6379, + 'timeout' => 0, + 'async' => false, + 'persistent' => false, + 'database' => 0, ]; /** diff --git a/system/Cache/Handlers/PredisHandler.php b/system/Cache/Handlers/PredisHandler.php index 250ea74a88e0..fd3274c3d8b0 100644 --- a/system/Cache/Handlers/PredisHandler.php +++ b/system/Cache/Handlers/PredisHandler.php @@ -36,15 +36,19 @@ class PredisHandler extends BaseHandler * host: string, * password: string|null, * port: int, + * async: bool + * persistent: bool * timeout: int * } */ protected $config = [ - 'scheme' => 'tcp', - 'host' => '127.0.0.1', - 'password' => null, - 'port' => 6379, - 'timeout' => 0, + 'scheme' => 'tcp', + 'host' => '127.0.0.1', + 'password' => null, + 'port' => 6379, + 'async' => false, + 'persistent' => false, + 'timeout' => 0, ]; /** diff --git a/user_guide_src/source/changelogs/v4.7.0.rst b/user_guide_src/source/changelogs/v4.7.0.rst index 809d56b41291..8a7e92c9b2dd 100644 --- a/user_guide_src/source/changelogs/v4.7.0.rst +++ b/user_guide_src/source/changelogs/v4.7.0.rst @@ -75,6 +75,7 @@ Libraries - **API Transformers:** This new feature provides a structured way to transform data for API responses. See :ref:`API Transformers ` for details. - **CLI:** Added ``SignalTrait`` to provide unified handling of operating system signals in CLI commands. +- **Cache:** Added ``async`` and ``persistent`` config item to predis handler. - **CURLRequest:** Added ``shareConnection`` config item to change default share connection. - **CURLRequest:** Added ``dns_cache_timeout`` option to change default DNS cache timeout. - **CURLRequest:** Added ``fresh_connect`` options to enable/disable request fresh connection. From b903ef2982b014bbb3b49527e1cd56ad458e59cf Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean Date: Mon, 10 Nov 2025 13:21:43 +0700 Subject: [PATCH 02/11] docs: update sample config --- system/Cache/Handlers/PredisHandler.php | 4 ++-- user_guide_src/source/libraries/caching/014.php | 13 ++++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/system/Cache/Handlers/PredisHandler.php b/system/Cache/Handlers/PredisHandler.php index fd3274c3d8b0..f7fd936abf59 100644 --- a/system/Cache/Handlers/PredisHandler.php +++ b/system/Cache/Handlers/PredisHandler.php @@ -36,8 +36,8 @@ class PredisHandler extends BaseHandler * host: string, * password: string|null, * port: int, - * async: bool - * persistent: bool + * async: bool, + * persistent: bool, * timeout: int * } */ diff --git a/user_guide_src/source/libraries/caching/014.php b/user_guide_src/source/libraries/caching/014.php index 6b0012696bf3..a7a2b8de74a9 100644 --- a/user_guide_src/source/libraries/caching/014.php +++ b/user_guide_src/source/libraries/caching/014.php @@ -9,11 +9,14 @@ class Cache extends BaseConfig // ... public $redis = [ - 'host' => '127.0.0.1', - 'password' => null, - 'port' => 6379, - 'timeout' => 0, - 'database' => 0, + 'scheme' => 'tcp', + 'host' => '127.0.0.1', + 'password' => null, + 'port' => 6379, + 'async' => false, + 'persistent' => false, + 'timeout' => 0, + 'database' => 0, ]; // ... From 25fd0ee02ad85c46f43cc417d5be1a4f8aecbb6a Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean Date: Mon, 10 Nov 2025 14:07:15 +0700 Subject: [PATCH 03/11] refactor: phpdocs on cache --- app/Config/Cache.php | 10 +++++++++- user_guide_src/source/libraries/caching/014.php | 1 - 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/Config/Cache.php b/app/Config/Cache.php index 0cf34985a4ac..c40aebf50ae8 100644 --- a/app/Config/Cache.php +++ b/app/Config/Cache.php @@ -112,7 +112,15 @@ class Cache extends BaseConfig * Your Redis server can be specified below, if you are using * the Redis or Predis drivers. * - * @var array{host?: string, password?: string|null, port?: int, timeout?: int, async?: bool, persistent?: bool, database?: int} + * @var array{ + * host?: string, + * password?: string|null, + * port?: int, + * timeout?: int, + * async?: bool, + * persistent?: bool, + * database?: int + * } */ public array $redis = [ 'host' => '127.0.0.1', diff --git a/user_guide_src/source/libraries/caching/014.php b/user_guide_src/source/libraries/caching/014.php index a7a2b8de74a9..810448b4f6cc 100644 --- a/user_guide_src/source/libraries/caching/014.php +++ b/user_guide_src/source/libraries/caching/014.php @@ -9,7 +9,6 @@ class Cache extends BaseConfig // ... public $redis = [ - 'scheme' => 'tcp', 'host' => '127.0.0.1', 'password' => null, 'port' => 6379, From 1e5e7e8bfee23a21ae00ed7888e40d08baf9bb45 Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean Date: Mon, 10 Nov 2025 14:48:46 +0700 Subject: [PATCH 04/11] feat: redis can used persistent --- system/Cache/Handlers/RedisHandler.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/system/Cache/Handlers/RedisHandler.php b/system/Cache/Handlers/RedisHandler.php index 3a13ee07f8e4..29225b67cd22 100644 --- a/system/Cache/Handlers/RedisHandler.php +++ b/system/Cache/Handlers/RedisHandler.php @@ -34,6 +34,7 @@ class RedisHandler extends BaseHandler * password: string|null, * port: int, * timeout: int, + * persistent: bool, * database: int, * } */ @@ -42,6 +43,7 @@ class RedisHandler extends BaseHandler 'password' => null, 'port' => 6379, 'timeout' => 0, + 'persistent' => false, 'database' => 0, ]; @@ -82,10 +84,11 @@ public function initialize() $this->redis = new Redis(); try { + $funcConnection = isset($config['persistent']) && $config['persistent'] ? 'pconnect' : 'connect'; + // Note:: If Redis is your primary cache choice, and it is "offline", every page load will end up been delayed by the timeout duration. // I feel like some sort of temporary flag should be set, to indicate that we think Redis is "offline", allowing us to bypass the timeout for a set period of time. - - if (! $this->redis->connect($config['host'], ($config['host'][0] === '/' ? 0 : $config['port']), $config['timeout'])) { + if (! $this->redis->$funcConnection($config['host'], ($config['host'][0] === '/' ? 0 : $config['port']), $config['timeout'])) { // Note:: I'm unsure if log_message() is necessary, however I'm not 100% comfortable removing it. log_message('error', 'Cache: Redis connection failed. Check your configuration.'); From 1b98969303d5d0dc042de40a44eb61996807dfc2 Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean Date: Mon, 10 Nov 2025 14:50:02 +0700 Subject: [PATCH 05/11] docs: added support persistent redis option --- user_guide_src/source/changelogs/v4.7.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/user_guide_src/source/changelogs/v4.7.0.rst b/user_guide_src/source/changelogs/v4.7.0.rst index 8a7e92c9b2dd..a691b6faf093 100644 --- a/user_guide_src/source/changelogs/v4.7.0.rst +++ b/user_guide_src/source/changelogs/v4.7.0.rst @@ -76,6 +76,7 @@ Libraries - **API Transformers:** This new feature provides a structured way to transform data for API responses. See :ref:`API Transformers ` for details. - **CLI:** Added ``SignalTrait`` to provide unified handling of operating system signals in CLI commands. - **Cache:** Added ``async`` and ``persistent`` config item to predis handler. +- **Cache:** Added ``persistent`` config item to redis handler. - **CURLRequest:** Added ``shareConnection`` config item to change default share connection. - **CURLRequest:** Added ``dns_cache_timeout`` option to change default DNS cache timeout. - **CURLRequest:** Added ``fresh_connect`` options to enable/disable request fresh connection. From a07efc6386478110c41f01ccabf3dfbc9fbc34b6 Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean Date: Mon, 10 Nov 2025 14:53:01 +0700 Subject: [PATCH 06/11] run cs-fixer --- system/Cache/Handlers/RedisHandler.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/system/Cache/Handlers/RedisHandler.php b/system/Cache/Handlers/RedisHandler.php index 29225b67cd22..a79c757fe331 100644 --- a/system/Cache/Handlers/RedisHandler.php +++ b/system/Cache/Handlers/RedisHandler.php @@ -39,12 +39,12 @@ class RedisHandler extends BaseHandler * } */ protected $config = [ - 'host' => '127.0.0.1', - 'password' => null, - 'port' => 6379, - 'timeout' => 0, + 'host' => '127.0.0.1', + 'password' => null, + 'port' => 6379, + 'timeout' => 0, 'persistent' => false, - 'database' => 0, + 'database' => 0, ]; /** @@ -88,7 +88,7 @@ public function initialize() // Note:: If Redis is your primary cache choice, and it is "offline", every page load will end up been delayed by the timeout duration. // I feel like some sort of temporary flag should be set, to indicate that we think Redis is "offline", allowing us to bypass the timeout for a set period of time. - if (! $this->redis->$funcConnection($config['host'], ($config['host'][0] === '/' ? 0 : $config['port']), $config['timeout'])) { + if (! $this->redis->{$funcConnection}($config['host'], ($config['host'][0] === '/' ? 0 : $config['port']), $config['timeout'])) { // Note:: I'm unsure if log_message() is necessary, however I'm not 100% comfortable removing it. log_message('error', 'Cache: Redis connection failed. Check your configuration.'); From e80bd540a33c32113f742f0615c0a84b966d72e4 Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean Date: Mon, 10 Nov 2025 15:07:25 +0700 Subject: [PATCH 07/11] docs: notes async option only used by Predis --- app/Config/Cache.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Config/Cache.php b/app/Config/Cache.php index c40aebf50ae8..1386bbfe1b85 100644 --- a/app/Config/Cache.php +++ b/app/Config/Cache.php @@ -127,7 +127,7 @@ class Cache extends BaseConfig 'password' => null, 'port' => 6379, 'timeout' => 0, - 'async' => false, + 'async' => false, // this option only used by Predis 'persistent' => false, 'database' => 0, ]; From 2754b722ddb4665281815772b8cdf7be3d4b5b10 Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean <97607754+ddevsr@users.noreply.github.com> Date: Mon, 17 Nov 2025 08:42:55 +0700 Subject: [PATCH 08/11] Update app/Config/Cache.php Co-authored-by: Michal Sniatala --- app/Config/Cache.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Config/Cache.php b/app/Config/Cache.php index 1386bbfe1b85..1f0f2a904f5b 100644 --- a/app/Config/Cache.php +++ b/app/Config/Cache.php @@ -127,7 +127,7 @@ class Cache extends BaseConfig 'password' => null, 'port' => 6379, 'timeout' => 0, - 'async' => false, // this option only used by Predis + 'async' => false, // specific to Predis and ignored by the native Redis extension 'persistent' => false, 'database' => 0, ]; From 24925c0579f20af3c53cae18d3cdf6362d2f5de6 Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean <97607754+ddevsr@users.noreply.github.com> Date: Mon, 17 Nov 2025 08:43:06 +0700 Subject: [PATCH 09/11] Update user_guide_src/source/changelogs/v4.7.0.rst Co-authored-by: Michal Sniatala --- user_guide_src/source/changelogs/v4.7.0.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/user_guide_src/source/changelogs/v4.7.0.rst b/user_guide_src/source/changelogs/v4.7.0.rst index a691b6faf093..466c67164a44 100644 --- a/user_guide_src/source/changelogs/v4.7.0.rst +++ b/user_guide_src/source/changelogs/v4.7.0.rst @@ -75,8 +75,8 @@ Libraries - **API Transformers:** This new feature provides a structured way to transform data for API responses. See :ref:`API Transformers ` for details. - **CLI:** Added ``SignalTrait`` to provide unified handling of operating system signals in CLI commands. -- **Cache:** Added ``async`` and ``persistent`` config item to predis handler. -- **Cache:** Added ``persistent`` config item to redis handler. +- **Cache:** Added ``async`` and ``persistent`` config item to Predis handler. +- **Cache:** Added ``persistent`` config item to Redis handler. - **CURLRequest:** Added ``shareConnection`` config item to change default share connection. - **CURLRequest:** Added ``dns_cache_timeout`` option to change default DNS cache timeout. - **CURLRequest:** Added ``fresh_connect`` options to enable/disable request fresh connection. From 42c27b0b306771f6b29f9641b14c9d20f63fedd4 Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean <97607754+ddevsr@users.noreply.github.com> Date: Mon, 17 Nov 2025 08:43:15 +0700 Subject: [PATCH 10/11] Update user_guide_src/source/libraries/caching/014.php Co-authored-by: Michal Sniatala --- user_guide_src/source/libraries/caching/014.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/libraries/caching/014.php b/user_guide_src/source/libraries/caching/014.php index 810448b4f6cc..c7be7cf0f076 100644 --- a/user_guide_src/source/libraries/caching/014.php +++ b/user_guide_src/source/libraries/caching/014.php @@ -12,7 +12,7 @@ class Cache extends BaseConfig 'host' => '127.0.0.1', 'password' => null, 'port' => 6379, - 'async' => false, + 'async' => false, // specific to Predis and ignored by the native Redis extension 'persistent' => false, 'timeout' => 0, 'database' => 0, From 7385984c019ea3bfb7a96285e5409ce369845a29 Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean <97607754+ddevsr@users.noreply.github.com> Date: Mon, 17 Nov 2025 20:41:31 +0700 Subject: [PATCH 11/11] Update app/Config/Cache.php Co-authored-by: John Paul E. Balandan, CPA --- app/Config/Cache.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/Config/Cache.php b/app/Config/Cache.php index 1f0f2a904f5b..f2077c9d29b0 100644 --- a/app/Config/Cache.php +++ b/app/Config/Cache.php @@ -113,13 +113,13 @@ class Cache extends BaseConfig * the Redis or Predis drivers. * * @var array{ - * host?: string, - * password?: string|null, - * port?: int, - * timeout?: int, - * async?: bool, - * persistent?: bool, - * database?: int + * host?: string, + * password?: string|null, + * port?: int, + * timeout?: int, + * async?: bool, + * persistent?: bool, + * database?: int * } */ public array $redis = [