Allow passing existing redis connections to MD_STD_CACHE
This commit is contained in:
parent
bbac217aa0
commit
c38f0146dc
|
@ -57,16 +57,23 @@ final class MD_STD_CACHE {
|
|||
*
|
||||
* @param string $redisKey Key to cache by in redis.
|
||||
* @param integer $expiry Expiration time in seconds.
|
||||
* @param Redis|null $redis Redis connection already opened, if one exists.
|
||||
* If this parameter is not provided, a separate
|
||||
* redis connection is opened for this function.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function serve_page_through_redis_cache(string $redisKey, int $expiry = 3600):string {
|
||||
public static function serve_page_through_redis_cache(string $redisKey, int $expiry = 3600, ?Redis $redis = null):string {
|
||||
|
||||
if (PHP_SAPI === 'cli') {
|
||||
return '';
|
||||
}
|
||||
|
||||
if ($redis === null) {
|
||||
$redis = self::open_redis_default();
|
||||
$closeRedis = true;
|
||||
}
|
||||
else $closeRedis = false;
|
||||
|
||||
if ($redis->ping() !== false) {
|
||||
|
||||
|
@ -94,7 +101,10 @@ final class MD_STD_CACHE {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
if ($closeRedis === true) {
|
||||
$redis->close();
|
||||
}
|
||||
|
||||
return '';
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user