Skip to content

Commit 42c3d4f

Browse files
minor symfony#21268 [Cache] Relax binary-constraint on Memcached connections (nicolas-grekas)
This PR was merged into the 3.3-dev branch. Discussion ---------- [Cache] Relax binary-constraint on Memcached connections | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - If it's green then it's PSR-6 compliant. Commits ------- 284d363 [Cache] Relax binary-constraint on Memcached connections
2 parents cc398db + 284d363 commit 42c3d4f

File tree

2 files changed

+5
-15
lines changed

2 files changed

+5
-15
lines changed

src/Symfony/Component/Cache/Adapter/MemcachedAdapter.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ public function __construct(\Memcached $client, $namespace = '', $defaultLifetim
4444
if (\Memcached::SERIALIZER_PHP !== $opt && \Memcached::SERIALIZER_IGBINARY !== $opt) {
4545
throw new CacheException('MemcachedAdapter: "serializer" option must be "php" or "igbinary".');
4646
}
47-
if (!$client->getOption(\Memcached::OPT_BINARY_PROTOCOL)) {
48-
throw new CacheException('MemcachedAdapter: "binary_protocol" option must be enabled.');
49-
}
5047
$this->maxIdLength -= strlen($client->getOption(\Memcached::OPT_PREFIX_KEY));
5148

5249
parent::__construct($namespace, $defaultLifetime);
@@ -67,7 +64,7 @@ public function __construct(\Memcached $client, $namespace = '', $defaultLifetim
6764
*
6865
* @return \Memcached
6966
*
70-
* @throws \ErrorEception When invalid options or servers are provided.
67+
* @throws \ErrorEception When invalid options or servers are provided
7168
*/
7269
public static function createConnection($servers, array $options = array())
7370
{

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

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public static function setupBeforeClass()
2929
if (!MemcachedAdapter::isSupported()) {
3030
self::markTestSkipped('Extension memcached >=2.2.0 required.');
3131
}
32-
self::$client = AbstractAdapter::createConnection('memcached://'.getenv('MEMCACHED_HOST'));
32+
self::$client = AbstractAdapter::createConnection('memcached://'.getenv('MEMCACHED_HOST'), array('binary_protocol' => false));
3333
self::$client->get('foo');
3434
$code = self::$client->getResultCode();
3535

@@ -40,7 +40,9 @@ public static function setupBeforeClass()
4040

4141
public function createCachePool($defaultLifetime = 0)
4242
{
43-
return new MemcachedAdapter(self::$client, str_replace('\\', '.', __CLASS__), $defaultLifetime);
43+
$client = $defaultLifetime ? AbstractAdapter::createConnection('memcached://'.getenv('MEMCACHED_HOST')) : self::$client;
44+
45+
return new MemcachedAdapter($client, str_replace('\\', '.', __CLASS__), $defaultLifetime);
4446
}
4547

4648
public function testOptions()
@@ -80,15 +82,6 @@ public function provideBadOptions()
8082
);
8183
}
8284

83-
/**
84-
* @expectedException \Symfony\Component\Cache\Exception\CacheException
85-
* @expectedExceptionMessage MemcachedAdapter: "binary_protocol" option must be enabled.
86-
*/
87-
public function testBinaryProtocol()
88-
{
89-
new MemcachedAdapter(MemcachedAdapter::createConnection(array(), array('binary_protocol' => false)));
90-
}
91-
9285
public function testDefaultOptions()
9386
{
9487
$this->assertTrue(MemcachedAdapter::isSupported());

0 commit comments

Comments
 (0)