Skip to content

Commit 45638a3

Browse files
committed
feat: added persistent config item to redis handler Session
1 parent 99c71e0 commit 45638a3

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

system/Session/Handlers/RedisHandler.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -142,17 +142,19 @@ protected function setSavePath(): void
142142
}
143143
}
144144

145-
$password = $query['auth'] ?? null;
146-
$database = isset($query['database']) ? (int) $query['database'] : 0;
147-
$timeout = isset($query['timeout']) ? (float) $query['timeout'] : 0.0;
148-
$prefix = $query['prefix'] ?? null;
145+
$persistent = $query['persistent'] ?? null;
146+
$password = $query['auth'] ?? null;
147+
$database = isset($query['database']) ? (int) $query['database'] : 0;
148+
$timeout = isset($query['timeout']) ? (float) $query['timeout'] : 0.0;
149+
$prefix = $query['prefix'] ?? null;
149150

150151
$this->savePath = [
151-
'host' => $host,
152-
'port' => $port,
153-
'password' => $password,
154-
'database' => $database,
155-
'timeout' => $timeout,
152+
'host' => $host,
153+
'port' => $port,
154+
'password' => $password,
155+
'database' => $database,
156+
'timeout' => $timeout,
157+
'persistent' => $persistent,
156158
];
157159

158160
if ($prefix !== null) {
@@ -176,8 +178,10 @@ public function open($path, $name): bool
176178

177179
$redis = new Redis();
178180

181+
$funcConnection = isset($this->savePath['persistent']) && $this->savePath['persistent'] ? 'pconnect' : 'connect';
182+
179183
if (
180-
! $redis->connect(
184+
! $redis->{$funcConnection}(
181185
$this->savePath['host'],
182186
$this->savePath['port'],
183187
$this->savePath['timeout'],

user_guide_src/source/changelogs/v4.7.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ Libraries
8585
- **Image:** The ``ImageMagickHandler`` has been rewritten to rely solely on the PHP ``imagick`` extension.
8686
- **Image:** Added ``ImageMagickHandler::clearMetadata()`` method to remove image metadata for privacy protection.
8787
- **ResponseTrait:** Added ``paginate``` method to simplify paginated API responses. See :ref:`ResponseTrait::paginate() <api_response_trait_paginate>` for details.
88+
- **Session:** Added ``persistent`` config item to redis handler.
8889
- **Time:** added methods ``Time::addCalendarMonths()`` and ``Time::subCalendarMonths()``
8990

9091
Commands

0 commit comments

Comments
 (0)