diff --git a/lib/private/Memcache/Redis.php b/lib/private/Memcache/Redis.php index 8195a6795a4..0d9eeffa0a7 100644 --- a/lib/private/Memcache/Redis.php +++ b/lib/private/Memcache/Redis.php @@ -8,6 +8,7 @@ namespace OC\Memcache; +use OC\RedisFactory; use OCP\IMemcacheTTL; use OCP\Server; @@ -38,24 +39,18 @@ class Redis extends Cache implements IMemcacheTTL { private const MAX_TTL = 30 * 24 * 60 * 60; // 1 month - /** - * @var \Redis|\RedisCluster $cache - */ - private static $cache = null; + private \Redis|\RedisCluster $cache; public function __construct($prefix = '', string $logFile = '') { parent::__construct($prefix); + $this->cache = \OCP\Server::get(RedisFactory::class)->getInstance(); } /** - * @return \Redis|\RedisCluster|null * @throws \Exception */ - public function getCache() { - if (is_null(self::$cache)) { - self::$cache = Server::get('RedisFactory')->getInstance(); - } - return self::$cache; + public function getCache(): \Redis|\RedisCluster { + return $this->cache; } #[\Override] diff --git a/lib/private/RedisFactory.php b/lib/private/RedisFactory.php index d2c81947b5c..722c356d9d8 100644 --- a/lib/private/RedisFactory.php +++ b/lib/private/RedisFactory.php @@ -131,15 +131,14 @@ class RedisFactory { } public function getInstance(): \Redis|\RedisCluster { - if (!$this->isAvailable()) { - throw new \Exception('Redis support is not available'); - } if ($this->instance === null) { + if (!$this->isAvailable()) { + throw new \Exception('Redis support is not available'); + } $this->create(); - } - - if ($this->instance === null) { - throw new \Exception('Redis support is not available'); + if ($this->instance === null) { + throw new \Exception('Redis support is not available'); + } } return $this->instance; diff --git a/lib/private/Server.php b/lib/private/Server.php index 5259e4cd42a..edbf8c225a6 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -660,10 +660,7 @@ class Server extends ServerContainer implements IServerContainer { }); $this->registerAlias(ICacheFactory::class, Factory::class); - $this->registerService('RedisFactory', function (Server $c) { - $systemConfig = $c->get(SystemConfig::class); - return new RedisFactory($systemConfig, $c->get(IEventLogger::class)); - }); + $this->registerDeprecatedAlias('RedisFactory', RedisFactory::class); $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { $l10n = $this->get(IFactory::class)->get('lib');