[BUGFIX] Make persistent connections available for Redis cache backend 78/50978/9
authorKasper Ligaard <kasperligaard+typo3.org@gmail.com>
Thu, 15 Dec 2016 13:59:26 +0000 (14:59 +0100)
committerMarkus Klein <markus.klein@typo3.org>
Sat, 14 Jan 2017 22:24:58 +0000 (23:24 +0100)
The Redis cache backend allows configuration of all connection
setting, except setting persistent connections. This omission
is fixed by this patch. Being unable to use persistent connections
under high load can hurt performance in cloud setups. Persistent
connections has been part of phpredis since 2010 and thus is
broadly available, but is impossible to use with TYPO3.

Resolves: #79005
Releases: master, 7.6
Change-Id: Ie5476e894072bb9979691f28bc7a1e10e86ef454
Reviewed-on: https://review.typo3.org/50978
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Kasper Ligaard <kasperligaard+typo3.org@gmail.com>
Reviewed-by: David Greiner <hallo@davidgreiner.de>
Tested-by: David Greiner <hallo@davidgreiner.de>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
typo3/sysext/core/Classes/Cache/Backend/RedisBackend.php
typo3/sysext/core/Documentation/Changelog/master/Important-79005-ConnectPersistentToRedisFromCacheBackend.rst [new file with mode: 0644]

index aaf81f6..74fe92a 100644 (file)
@@ -74,6 +74,13 @@ class RedisBackend extends AbstractBackend implements TaggableBackendInterface
     protected $connected = false;
 
     /**
+     * Persistent connection
+     *
+     * @var bool
+     */
+    protected $persistentConnection = false;
+
+    /**
      * Hostname / IP of the Redis server, defaults to 127.0.0.1.
      *
      * @var string
@@ -140,7 +147,11 @@ class RedisBackend extends AbstractBackend implements TaggableBackendInterface
     {
         $this->redis = new \Redis();
         try {
-            $this->connected = $this->redis->connect($this->hostname, $this->port);
+            if ($this->persistentConnection) {
+                $this->connected = $this->redis->pconnect($this->hostname, $this->port);
+            } else {
+                $this->connected = $this->redis->connect($this->hostname, $this->port);
+            }
         } catch (\Exception $e) {
             \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog('Could not connect to redis server.', 'core', \TYPO3\CMS\Core\Utility\GeneralUtility::SYSLOG_SEVERITY_ERROR);
         }
@@ -161,6 +172,18 @@ class RedisBackend extends AbstractBackend implements TaggableBackendInterface
     }
 
     /**
+     * Setter for persistent connection
+     *
+     * @param bool $persistentConnection
+     * @return void
+     * @api
+     */
+    public function setPersistentConnection($persistentConnection)
+    {
+        $this->persistentConnection = $persistentConnection;
+    }
+
+    /**
      * Setter for server hostname
      *
      * @param string $hostname Hostname
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Important-79005-ConnectPersistentToRedisFromCacheBackend.rst b/typo3/sysext/core/Documentation/Changelog/master/Important-79005-ConnectPersistentToRedisFromCacheBackend.rst
new file mode 100644 (file)
index 0000000..0adbc92
--- /dev/null
@@ -0,0 +1,26 @@
+.. include:: ../../Includes.txt
+
+=============================================================================================
+Important: #79005 - Included missing support for persistent connection in Redis cache backend
+=============================================================================================
+
+See :issue:`79005`
+
+Description
+===========
+
+phpredis has support for persistent connections, but currently the Redis cache backend has hard-coded
+the regular connect call. For unknown reasons - possibly a simple oversight - this is the only
+connection setting missing from the Redis cache backend is now implemented.
+
+The configuration setting is named ``persistentConnection``. It is an optional boolean option.
+
+For other configuration options see https://docs.typo3.org/typo3cms/CoreApiReference/CachingFramework/FrontendsBackends/Index.html#redis-backend
+
+Impact
+======
+
+None. Non-persistent connections remain the default.
+
+
+.. index:: LocalConfiguration
\ No newline at end of file