Skip to content

Commit

Permalink
[Cache] added support for phpredis 4 compression and `tcp_keepalive…
Browse files Browse the repository at this point in the history
…` options
  • Loading branch information
nicolas-grekas committed Jun 20, 2018
1 parent a4f5c6e commit 2ff02cd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Symfony/Component/Cache/CHANGELOG.md
Expand Up @@ -6,6 +6,7 @@ CHANGELOG

* added `CacheInterface`, which provides stampede protection via probabilistic early expiration and should become the preferred way to use a cache
* added sub-second expiry accuracy for backends that support it
* added support for phpredis 4 `compression` and `tcp_keepalive` options
* throw `LogicException` when `CacheItem::tag()` is called on an item coming from a non tag-aware pool
* deprecated `CacheItem::getPreviousTags()`, use `CacheItem::getMetadata()` instead
* deprecated the `AbstractAdapter::createSystemCache()` method
Expand Down
Expand Up @@ -44,6 +44,8 @@ public function testCreateConnection()
'persistent_id' => null,
'read_timeout' => 0,
'retry_interval' => 0,
'compression' => true,
'tcp_keepalive' => 0,
'lazy' => false,
'database' => '1',
'password' => null,
Expand Down
9 changes: 9 additions & 0 deletions src/Symfony/Component/Cache/Traits/RedisTrait.php
Expand Up @@ -34,6 +34,8 @@ trait RedisTrait
'timeout' => 30,
'read_timeout' => 0,
'retry_interval' => 0,
'compression' => true,
'tcp_keepalive' => 0,
'lazy' => false,
);
private $redis;
Expand Down Expand Up @@ -142,6 +144,13 @@ public static function createConnection($dsn, array $options = array())
throw new InvalidArgumentException(sprintf('Redis connection failed (%s): %s', $e, $dsn));
}

if (0 < $params['tcp_keepalive'] && \defined('Redis::OPT_TCP_KEEPALIVE')) {
$redis->setOption(\Redis::OPT_TCP_KEEPALIVE, $params['tcp_keepalive']);
}
if ($params['compression'] && \defined('Redis::COMPRESSION_LZF')) {
$redis->setOption(\Redis::OPT_COMPRESSION, \Redis::COMPRESSION_LZF);
}

return true;
};

Expand Down

0 comments on commit 2ff02cd

Please sign in to comment.