Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions app/Config/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,24 @@ 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, // this option only used by Predis
'persistent' => false,
'database' => 0,
];

/**
Expand Down
14 changes: 9 additions & 5 deletions system/Cache/Handlers/PredisHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];

/**
Expand Down
17 changes: 10 additions & 7 deletions system/Cache/Handlers/RedisHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,17 @@ class RedisHandler extends BaseHandler
* password: string|null,
* port: int,
* timeout: int,
* persistent: bool,
* database: int,
* }
*/
protected $config = [
'host' => '127.0.0.1',
'password' => null,
'port' => 6379,
'timeout' => 0,
'database' => 0,
'host' => '127.0.0.1',
'password' => null,
'port' => 6379,
'timeout' => 0,
'persistent' => false,
'database' => 0,
];

/**
Expand Down Expand Up @@ -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.');

Expand Down
2 changes: 2 additions & 0 deletions user_guide_src/source/changelogs/v4.7.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ Libraries

- **API Transformers:** This new feature provides a structured way to transform data for API responses. See :ref:`API Transformers <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.
Expand Down
12 changes: 7 additions & 5 deletions user_guide_src/source/libraries/caching/014.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ class Cache extends BaseConfig
// ...

public $redis = [
'host' => '127.0.0.1',
'password' => null,
'port' => 6379,
'timeout' => 0,
'database' => 0,
'host' => '127.0.0.1',
'password' => null,
'port' => 6379,
'async' => false,
'persistent' => false,
'timeout' => 0,
'database' => 0,
];

// ...
Expand Down
Loading