Skip to content

Commit

Permalink
feature #27646 [Cache] added support for phpredis 4 compression and…
Browse files Browse the repository at this point in the history
… `tcp_keepalive` options (nicolas-grekas)

This PR was merged into the 4.2-dev branch.

Discussion
----------

[Cache] added support for phpredis 4 `compression` and `tcp_keepalive` options

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

See https://pecl.php.net/package-changelog.php?package=redis

Commits
-------

2ff02cd [Cache] added support for phpredis 4 `compression` and `tcp_keepalive` options
  • Loading branch information
fabpot committed Jun 20, 2018
2 parents 1dac82a + 2ff02cd commit bc8d4f6
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 bc8d4f6

Please sign in to comment.