From 9fa0ec148e1ba3cd64b09b53809b967cb38e0649 Mon Sep 17 00:00:00 2001 From: Stiliyan Ivanov Date: Mon, 2 Nov 2026 18:51:49 +0200 Subject: [PATCH 1/4] fix: Update get method documentation and handle non-existent cache keys in Redis driver --- system/libraries/Cache/drivers/Cache_redis.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/system/libraries/Cache/drivers/Cache_redis.php b/system/libraries/Cache/drivers/Cache_redis.php index d84437b591..0d9addf873 100644 --- a/system/libraries/Cache/drivers/Cache_redis.php +++ b/system/libraries/Cache/drivers/Cache_redis.php @@ -157,7 +157,7 @@ public function __construct() * Get cache * * @param string $key Cache ID - * @return mixed + * @return mixed Cached value or NULL if the key does not exist */ public function get($key) { @@ -168,6 +168,12 @@ public function get($key) return $this->_get_v31($key); } + // hMGet() returns FALSE for every field when the key does not exist + if ($data['__ci_type'] === FALSE) + { + return NULL; + } + switch ($data['__ci_type']) { case 'array': From 4bbda78f4efdef4377b008eb7f7913074dadfbb3 Mon Sep 17 00:00:00 2001 From: Stiliyan Ivanov Date: Mon, 2 Nov 2026 19:00:44 +0200 Subject: [PATCH 2/4] fix: Update get method to handle settype() failures and improve error handling --- system/libraries/Cache/drivers/Cache_redis.php | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/system/libraries/Cache/drivers/Cache_redis.php b/system/libraries/Cache/drivers/Cache_redis.php index 0d9addf873..60a2aa0a91 100644 --- a/system/libraries/Cache/drivers/Cache_redis.php +++ b/system/libraries/Cache/drivers/Cache_redis.php @@ -157,7 +157,8 @@ public function __construct() * Get cache * * @param string $key Cache ID - * @return mixed Cached value or NULL if the key does not exist + * @return mixed Cached value or NULL if the key does not exist or settype() fails + * @throws ValueError If settype() is given an invalid type (PHP 8+) */ public function get($key) { @@ -168,12 +169,6 @@ public function get($key) return $this->_get_v31($key); } - // hMGet() returns FALSE for every field when the key does not exist - if ($data['__ci_type'] === FALSE) - { - return NULL; - } - switch ($data['__ci_type']) { case 'array': @@ -186,10 +181,10 @@ public function get($key) case 'NULL': return settype($data['__ci_value'], $data['__ci_type']) ? $data['__ci_value'] - : FALSE; + : NULL; case 'resource': default: - return FALSE; + return NULL; } } From 6695c8c12b30711269a4132fadd0b2613ef987da Mon Sep 17 00:00:00 2001 From: Stiliyan Ivanov Date: Mon, 2 Nov 2026 19:35:11 +0200 Subject: [PATCH 3/4] fix: Update get method documentation to clarify return values for cache retrieval --- system/libraries/Cache/drivers/Cache_redis.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/libraries/Cache/drivers/Cache_redis.php b/system/libraries/Cache/drivers/Cache_redis.php index 60a2aa0a91..619c81d018 100644 --- a/system/libraries/Cache/drivers/Cache_redis.php +++ b/system/libraries/Cache/drivers/Cache_redis.php @@ -157,7 +157,7 @@ public function __construct() * Get cache * * @param string $key Cache ID - * @return mixed Cached value or NULL if the key does not exist or settype() fails + * @return mixed Cached value or NULL (FALSE cached by 3.1.x) if the key does not exist or NULL if settype() fails * @throws ValueError If settype() is given an invalid type (PHP 8+) */ public function get($key) From f93e7d689b5883897971fa534be0273d497a5aad Mon Sep 17 00:00:00 2001 From: Stiliyan Ivanov Date: Tue, 3 Nov 2026 00:05:49 +0200 Subject: [PATCH 4/4] Improve documentation for get method return type Updated the return type documentation for the get method to clarify possible return values. --- system/libraries/Cache/drivers/Cache_redis.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/system/libraries/Cache/drivers/Cache_redis.php b/system/libraries/Cache/drivers/Cache_redis.php index 619c81d018..da5bec6c96 100644 --- a/system/libraries/Cache/drivers/Cache_redis.php +++ b/system/libraries/Cache/drivers/Cache_redis.php @@ -157,7 +157,8 @@ public function __construct() * Get cache * * @param string $key Cache ID - * @return mixed Cached value or NULL (FALSE cached by 3.1.x) if the key does not exist or NULL if settype() fails + * @return mixed Cached value, NULL for a missing key, unsupported type or failed conversion; + * FALSE if unserialization fails or the legacy Redis GET fallback returns FALSE * @throws ValueError If settype() is given an invalid type (PHP 8+) */ public function get($key)