8000 feature #27646 [Cache] added support for phpredis 4 `compression` and… · symfony/symfony@bc8d4f6 · GitHub
[go: up one dir, main page]

Skip to content

Commit bc8d4f6

Browse files
committed
feature #27646 [Cache] added support for phpredis 4 compression and 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
2 parents 1dac82a + 2ff02cd commit bc8d4f6

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

src/Symfony/Component/Cache/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CHANGELOG
66

77
* added `CacheInterface`, which provides stampede protection via probabilistic early expiration and should become the preferred way to use a cache
88
* added sub-second expiry accuracy for backends that support it
9+
* added support for phpredis 4 `compression` and `tcp_keepalive` options
910
* throw `LogicException` when `CacheItem::tag()` is called on an item coming from a non tag-aware pool
1011
* deprecated `CacheItem::getPreviousTags()`, use `CacheItem::getMetadata()` instead
1112
* deprecated the `AbstractAdapter::createSystemCache()` method

src/Symfony/Component/Cache/Tests/Adapter/PredisAdapterTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ public function testCreateConnection()
4444
'persistent_id' => null,
4545
'read_timeout' => 0,
4646
'retry_interval' => 0,
47+
'compression' => true,
48+
'tcp_keepalive' => 0,
4749
'lazy' => false,
4850
'database' => '1',
4951
'password' => null,

src/Symfony/Component/Cache/Traits/RedisTrait.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ trait RedisTrait
3434
'timeout' => 30,
3535
'read_timeout' => 0,
3636
'retry_interval' => 0,
37+
'compression' => true,
38+
'tcp_keepalive' => 0,
3739
'lazy' => false,
3840
);
3941
private $redis;
@@ -142,6 +144,13 @@ public static function createConnection($dsn, array $options = array())
142144
throw new InvalidArgumentException(sprintf('Redis connection failed (%s): %s', $e, $dsn));
143145
}
144146

147+
if (0 < $params['tcp_keepalive'] && \defined('Redis::OPT_TCP_KEEPALIVE')) {
148+
$redis->setOption(\Redis::OPT_TCP_KEEPALIVE, $params['tcp_keepalive']);
149+
}
150+
if ($params['compression'] && \defined('Redis::COMPRESSION_LZF')) {
151+
$redis->setOption(\Redis::OPT_COMPRESSION, \Redis::COMPRESSION_LZF);
152+
}
153+
145154
return true;
146155
};
147156

0 commit comments

Comments
 (0)
0