mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Fixing issue where when multiple Memcache servers were being specified, only first would make it. Adding tests. Fixes #5767
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7879 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
8759f4ae28
commit
ffab7024f0
2 changed files with 48 additions and 16 deletions
7
cake/libs/cache/memcache.php
vendored
7
cake/libs/cache/memcache.php
vendored
|
@ -72,6 +72,7 @@ class MemcacheEngine extends CacheEngine {
|
|||
$this->settings['servers'] = array($this->settings['servers']);
|
||||
}
|
||||
if (!isset($this->__Memcache)) {
|
||||
$return = false;
|
||||
$this->__Memcache =& new Memcache();
|
||||
foreach ($this->settings['servers'] as $server) {
|
||||
$parts = explode(':', $server);
|
||||
|
@ -81,10 +82,10 @@ class MemcacheEngine extends CacheEngine {
|
|||
$port = $parts[1];
|
||||
}
|
||||
if ($this->__Memcache->addServer($host, $port)) {
|
||||
return true;
|
||||
$return = true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return $return;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -154,4 +155,4 @@ class MemcacheEngine extends CacheEngine {
|
|||
return true;
|
||||
}
|
||||
}
|
||||
?>
|
||||
?>
|
||||
|
|
57
cake/tests/cases/libs/cache/memcache.test.php
vendored
57
cake/tests/cases/libs/cache/memcache.test.php
vendored
|
@ -38,7 +38,7 @@ if (!class_exists('Cache')) {
|
|||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.cache
|
||||
*/
|
||||
class MemcacheEngineTest extends UnitTestCase {
|
||||
class MemcacheEngineTest extends CakeTestCase {
|
||||
/**
|
||||
* skip method
|
||||
*
|
||||
|
@ -47,10 +47,10 @@ class MemcacheEngineTest extends UnitTestCase {
|
|||
*/
|
||||
function skip() {
|
||||
$skip = true;
|
||||
if ($result = Cache::engine('Memcache')) {
|
||||
if (Cache::engine('Memcache')) {
|
||||
$skip = false;
|
||||
}
|
||||
$this->skipif($skip, 'Memcache is not installed or configured properly');
|
||||
$this->skipIf($skip, 'Memcache is not installed or configured properly');
|
||||
}
|
||||
/**
|
||||
* setUp method
|
||||
|
@ -61,6 +61,15 @@ class MemcacheEngineTest extends UnitTestCase {
|
|||
function setUp() {
|
||||
Cache::config('memcache', array('engine'=>'Memcache', 'prefix' => 'cake_'));
|
||||
}
|
||||
/**
|
||||
* tearDown method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function tearDown() {
|
||||
Cache::config('default');
|
||||
}
|
||||
/**
|
||||
* testSettings method
|
||||
*
|
||||
|
@ -78,6 +87,37 @@ class MemcacheEngineTest extends UnitTestCase {
|
|||
);
|
||||
$this->assertEqual($settings, $expecting);
|
||||
}
|
||||
/**
|
||||
* testSettings method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testMultipleServers() {
|
||||
$servers = array('127.0.0.1:11211', '127.0.0.1:11222');
|
||||
|
||||
$Cache =& Cache::getInstance();
|
||||
$MemCache =& $Cache->_Engine['Memcache'];
|
||||
|
||||
$available = true;
|
||||
foreach($servers as $server) {
|
||||
list($host, $port) = explode(':', $server);
|
||||
if (!@$MemCache->__Memcache->connect($host, $port)) {
|
||||
$available = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->skipIf(!$available, 'Need memcache servers at ' . implode(', ', $servers) . ' to run this test')) {
|
||||
return;
|
||||
}
|
||||
|
||||
unset($MemCache->__Memcache);
|
||||
$MemCache->init(array('engine' => 'Memcache', 'servers' => $servers));
|
||||
|
||||
$servers = array_keys($MemCache->__Memcache->getExtendedStats());
|
||||
$settings = Cache::settings();
|
||||
$this->assertEqual($servers, $settings['servers']);
|
||||
}
|
||||
/**
|
||||
* testConnect method
|
||||
*
|
||||
|
@ -165,14 +205,5 @@ class MemcacheEngineTest extends UnitTestCase {
|
|||
$result = Cache::delete('delete_test');
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
/**
|
||||
* tearDown method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function tearDown() {
|
||||
Cache::config('default');
|
||||
}
|
||||
}
|
||||
?>
|
||||
?>
|
||||
|
|
Loading…
Add table
Reference in a new issue