[Cache] Relax binary-constraint on Memcached connections

This commit is contained in:
Nicolas Grekas 2017-01-13 08:33:21 +01:00
parent 136a5ffc55
commit 284d363fb1
2 changed files with 5 additions and 15 deletions

View File

@ -44,9 +44,6 @@ class MemcachedAdapter extends AbstractAdapter
if (\Memcached::SERIALIZER_PHP !== $opt && \Memcached::SERIALIZER_IGBINARY !== $opt) { if (\Memcached::SERIALIZER_PHP !== $opt && \Memcached::SERIALIZER_IGBINARY !== $opt) {
throw new CacheException('MemcachedAdapter: "serializer" option must be "php" or "igbinary".'); 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)); $this->maxIdLength -= strlen($client->getOption(\Memcached::OPT_PREFIX_KEY));
parent::__construct($namespace, $defaultLifetime); parent::__construct($namespace, $defaultLifetime);
@ -67,7 +64,7 @@ class MemcachedAdapter extends AbstractAdapter
* *
* @return \Memcached * @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()) public static function createConnection($servers, array $options = array())
{ {

View File

@ -29,7 +29,7 @@ class MemcachedAdapterTest extends AdapterTestCase
if (!MemcachedAdapter::isSupported()) { if (!MemcachedAdapter::isSupported()) {
self::markTestSkipped('Extension memcached >=2.2.0 required.'); 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'); self::$client->get('foo');
$code = self::$client->getResultCode(); $code = self::$client->getResultCode();
@ -40,7 +40,9 @@ class MemcachedAdapterTest extends AdapterTestCase
public function createCachePool($defaultLifetime = 0) 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() public function testOptions()
@ -80,15 +82,6 @@ class MemcachedAdapterTest extends AdapterTestCase
); );
} }
/**
* @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() public function testDefaultOptions()
{ {
$this->assertTrue(MemcachedAdapter::isSupported()); $this->assertTrue(MemcachedAdapter::isSupported());