From af0699012ae02accb11b4b3a8d5b3fee477ceb46 Mon Sep 17 00:00:00 2001 From: Aleksey Prilipko Date: Sun, 20 May 2018 12:18:30 +1000 Subject: [PATCH] bug #27299 [Cache] memcache connect should not add duplicate entries on sequential calls --- .../Component/Cache/Tests/Simple/MemcachedCacheTest.php | 9 +++++++++ src/Symfony/Component/Cache/Traits/MemcachedTrait.php | 6 +++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Cache/Tests/Simple/MemcachedCacheTest.php b/src/Symfony/Component/Cache/Tests/Simple/MemcachedCacheTest.php index c4af891af7ba7..b46d7e443dd20 100644 --- a/src/Symfony/Component/Cache/Tests/Simple/MemcachedCacheTest.php +++ b/src/Symfony/Component/Cache/Tests/Simple/MemcachedCacheTest.php @@ -45,6 +45,15 @@ public function createSimpleCache($defaultLifetime = 0) return new MemcachedCache($client, str_replace('\\', '.', __CLASS__), $defaultLifetime); } + public function testCreatePersistentConnectionShouldNotDupServerList() + { + $instance = MemcachedCache::createConnection('memcached://'.getenv('MEMCACHED_HOST'), array('persistent_id' => 'persistent')); + $this->assertCount(1, $instance->getServerList()); + + $instance = MemcachedCache::createConnection('memcached://'.getenv('MEMCACHED_HOST'), array('persistent_id' => 'persistent')); + $this->assertCount(1, $instance->getServerList()); + } + public function testOptions() { $client = MemcachedCache::createConnection(array(), array( diff --git a/src/Symfony/Component/Cache/Traits/MemcachedTrait.php b/src/Symfony/Component/Cache/Traits/MemcachedTrait.php index 9b877efb080a9..9148573694cf6 100644 --- a/src/Symfony/Component/Cache/Traits/MemcachedTrait.php +++ b/src/Symfony/Component/Cache/Traits/MemcachedTrait.php @@ -169,12 +169,12 @@ public static function createConnection($servers, array $options = array()) } if ($oldServers !== $newServers) { - // before resetting, ensure $servers is valid - $client->addServers($servers); $client->resetServerList(); + $client->addServers($servers); } + } else { + $client->addServers($servers); } - $client->addServers($servers); if (null !== $username || null !== $password) { if (!method_exists($client, 'setSaslAuthData')) {