Skip to content

Commit 1e5e7e8

Browse files
committed
feat: redis can used persistent
1 parent 25fd0ee commit 1e5e7e8

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

system/Cache/Handlers/RedisHandler.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class RedisHandler extends BaseHandler
3434
* password: string|null,
3535
* port: int,
3636
* timeout: int,
37+
* persistent: bool,
3738
* database: int,
3839
* }
3940
*/
@@ -42,6 +43,7 @@ class RedisHandler extends BaseHandler
4243
'password' => null,
4344
'port' => 6379,
4445
'timeout' => 0,
46+
'persistent' => false,
4547
'database' => 0,
4648
];
4749

@@ -82,10 +84,11 @@ public function initialize()
8284
$this->redis = new Redis();
8385

8486
try {
87+
$funcConnection = isset($config['persistent']) && $config['persistent'] ? 'pconnect' : 'connect';
88+
8589
// Note:: If Redis is your primary cache choice, and it is "offline", every page load will end up been delayed by the timeout duration.
8690
// 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.
87-
88-
if (! $this->redis->connect($config['host'], ($config['host'][0] === '/' ? 0 : $config['port']), $config['timeout'])) {
91+
if (! $this->redis->$funcConnection($config['host'], ($config['host'][0] === '/' ? 0 : $config['port']), $config['timeout'])) {
8992
// Note:: I'm unsure if log_message() is necessary, however I'm not 100% comfortable removing it.
9093
log_message('error', 'Cache: Redis connection failed. Check your configuration.');
9194

0 commit comments

Comments
 (0)