Skip to content

Commit

Permalink
minor #21268 [Cache] Relax binary-constraint on Memcached connections…
Browse files Browse the repository at this point in the history
… (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
  • Loading branch information
nicolas-grekas committed Jan 14, 2017
2 parents cc398db + 284d363 commit 42c3d4f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
5 changes: 1 addition & 4 deletions src/Symfony/Component/Cache/Adapter/MemcachedAdapter.php
Expand Up @@ -44,9 +44,6 @@ public function __construct(\Memcached $client, $namespace = '', $defaultLifetim
if (\Memcached::SERIALIZER_PHP !== $opt && \Memcached::SERIALIZER_IGBINARY !== $opt) {
throw new CacheException('MemcachedAdapter: "serializer" option must be "php" or "igbinary".');
}
if (!$client->getOption(\Memcached::OPT_BINARY_PROTOCOL)) {
throw new CacheException('MemcachedAdapter: "binary_protocol" option must be enabled.');
}
$this->maxIdLength -= strlen($client->getOption(\Memcached::OPT_PREFIX_KEY));

parent::__construct($namespace, $defaultLifetime);
Expand All @@ -67,7 +64,7 @@ public function __construct(\Memcached $client, $namespace = '', $defaultLifetim
*
* @return \Memcached
*
* @throws \ErrorEception When invalid options or servers are provided.
* @throws \ErrorEception When invalid options or servers are provided
*/
public static function createConnection($servers, array $options = array())
{
Expand Down
15 changes: 4 additions & 11 deletions src/Symfony/Component/Cache/Tests/Adapter/MemcachedAdapterTest.php
Expand Up @@ -29,7 +29,7 @@ public static function setupBeforeClass()
if (!MemcachedAdapter::isSupported()) {
self::markTestSkipped('Extension memcached >=2.2.0 required.');
}
self::$client = AbstractAdapter::createConnection('memcached://'.getenv('MEMCACHED_HOST'));
self::$client = AbstractAdapter::createConnection('memcached://'.getenv('MEMCACHED_HOST'), array('binary_protocol' => false));
self::$client->get('foo');
$code = self::$client->getResultCode();

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

public function createCachePool($defaultLifetime = 0)
{
return new MemcachedAdapter(self::$client, str_replace('\\', '.', __CLASS__), $defaultLifetime);
$client = $defaultLifetime ? AbstractAdapter::createConnection('memcached://'.getenv('MEMCACHED_HOST')) : self::$client;

return new MemcachedAdapter($client, str_replace('\\', '.', __CLASS__), $defaultLifetime);
}

public function testOptions()
Expand Down Expand Up @@ -80,15 +82,6 @@ public function provideBadOptions()
);
}

/**
* @expectedException \Symfony\Component\Cache\Exception\CacheException
* @expectedExceptionMessage MemcachedAdapter: "binary_protocol" option must be enabled.
*/
public function testBinaryProtocol()
{
new MemcachedAdapter(MemcachedAdapter::createConnection(array(), array('binary_protocol' => false)));
}

public function testDefaultOptions()
{
$this->assertTrue(MemcachedAdapter::isSupported());
Expand Down

0 comments on commit 42c3d4f

Please sign in to comment.