*/
public function connect() {
try {
- return parent::connect();
+ if ($this->_conn) {
+ return parent::connect();
+ }
+
+ // Only trigger the event logger for the initial connect call
+ $eventLogger = \OC::$server->getEventLogger();
+ $eventLogger->start('connect:db', 'db connection opened');
+ $status = parent::connect();
+ $eventLogger->end('connect:db');
+
+ return $status;
} catch (Exception $e) {
// throw a new exception to prevent leaking info from the stacktrace
throw new Exception('Failed to connect to the database: ' . $e->getMessage(), $e->getCode());
*/
namespace OC;
+use OCP\Diagnostics\IEventLogger;
+
class RedisFactory {
public const REDIS_MINIMAL_VERSION = '3.1.3';
public const REDIS_EXTRA_PARAMETERS_MINIMAL_VERSION = '5.3.0';
/** @var \Redis|\RedisCluster */
private $instance;
- /** @var SystemConfig */
- private $config;
+ private SystemConfig $config;
+
+ private IEventLogger $eventLogger;
/**
* RedisFactory constructor.
*
* @param SystemConfig $config
*/
- public function __construct(SystemConfig $config) {
+ public function __construct(SystemConfig $config, IEventLogger $eventLogger) {
$this->config = $config;
+ $this->eventLogger = $eventLogger;
}
private function create() {
$port = null;
}
+ $this->eventLogger->start('connect:redis', 'Connect to redis and send AUTH, SELECT');
// Support for older phpredis versions not supporting connectionParameters
if ($connectionParameters !== null) {
// Non-clustered redis requires connection parameters to be wrapped inside `stream`
if (isset($config['dbindex'])) {
$this->instance->select($config['dbindex']);
}
+ $this->eventLogger->end('connect:redis');
}
}
$this->registerService('RedisFactory', function (Server $c) {
$systemConfig = $c->get(SystemConfig::class);
- return new RedisFactory($systemConfig);
+ return new RedisFactory($systemConfig, $c->getEventLogger());
});
$this->registerService(\OCP\Activity\IManager::class, function (Server $c) {