Add settings check on redis and memcached

This commit is contained in:
Romain Neutron
2012-06-15 17:06:23 +02:00
parent 52798a9053
commit 61716677d2
2 changed files with 86 additions and 6 deletions

View File

@@ -72,7 +72,7 @@ class module_console_fileEnsureDevSetting extends Command
$this->configuration = \Alchemy\Phrasea\Core\Configuration::build($specifications, $environnement); $this->configuration = \Alchemy\Phrasea\Core\Configuration::build($specifications, $environnement);
$this->checkParse($output); $this->checkParse($output);
$output->writeln(sprintf("Will Ensure Production Settings on <info>%s</info>", $this->configuration->getEnvironnement())); $output->writeln(sprintf("Will Ensure Development Settings on <info>%s</info>", $this->configuration->getEnvironnement()));
$this->runTests($output); $this->runTests($output);
@@ -423,7 +423,7 @@ class module_console_fileEnsureDevSetting extends Command
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
} }
return false; return false;
@@ -707,6 +707,8 @@ class module_console_fileEnsureDevSetting extends Command
default: default:
break; break;
case 'memcache': case 'memcache':
case 'memcached':
case 'redis':
$required_options = array('host', 'port'); $required_options = array('host', 'port');
break; break;
} }
@@ -762,7 +764,14 @@ class module_console_fileEnsureDevSetting extends Command
return false; return false;
} }
if ($Service->getDriver()->isServer()) {
try {
$driver = $Service->getDriver();
} catch (\Exception $e) {
return false;
}
if ($driver->isServer()) {
switch ($Service->getType()) { switch ($Service->getType()) {
default: default:
return false; return false;
@@ -772,6 +781,38 @@ class module_console_fileEnsureDevSetting extends Command
return false; return false;
} }
break; break;
case 'memcached':
$ret = false;
try {
$memcached = new \Memcached();
$memcached->addServer($Service->getHost(), $Service->getPort());
$stats = $memcached->getStats();
if ( ! isset($stats[$key]) || ! $stats[$key]) {
throw new \Exception('Unable to connect to memcached server');
}
$ret = true;
} catch (\Exception $e) {
}
unset($memcached);
return $ret;
break;
case 'redis':
$ret = false;
try {
$redis = new \Redis();
if (@$redis->connect($Service->getHost(), $Service->getPort())) {
$ret = true;
}
} catch (\Exception $e) {
}
unset($redis);
return $ret;
break;
} }
} }

View File

@@ -148,7 +148,6 @@ class module_console_fileEnsureProductionSetting extends Command
{ {
$cache = $this->configuration->getCache(); $cache = $this->configuration->getCache();
if ($this->probeCacheService($output, $cache)) { if ($this->probeCacheService($output, $cache)) {
if ($this->recommendedCacheService($output, $cache, true)) { if ($this->recommendedCacheService($output, $cache, true)) {
$work_message = '<info>Works !</info>'; $work_message = '<info>Works !</info>';
@@ -412,7 +411,7 @@ class module_console_fileEnsureProductionSetting extends Command
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
} }
return false; return false;
@@ -705,6 +704,8 @@ class module_console_fileEnsureProductionSetting extends Command
default: default:
break; break;
case 'memcache': case 'memcache':
case 'memcached':
case 'redis':
$required_options = array('host', 'port'); $required_options = array('host', 'port');
break; break;
} }
@@ -760,7 +761,13 @@ class module_console_fileEnsureProductionSetting extends Command
return false; return false;
} }
if ($Service->getDriver()->isServer()) { try {
$driver = $Service->getDriver();
} catch (\Exception $e) {
return false;
}
if ($driver->isServer()) {
switch ($Service->getType()) { switch ($Service->getType()) {
default: default:
return false; return false;
@@ -770,6 +777,38 @@ class module_console_fileEnsureProductionSetting extends Command
return false; return false;
} }
break; break;
case 'memcached':
$ret = false;
try {
$memcached = new \Memcached();
$memcached->addServer($Service->getHost(), $Service->getPort());
$stats = $memcached->getStats();
if ( ! isset($stats[$key]) || ! $stats[$key]) {
throw new \Exception('Unable to connect to memcached server');
}
$ret = true;
} catch (\Exception $e) {
}
unset($memcached);
return $ret;
break;
case 'redis':
$ret = false;
try {
$redis = new \Redis();
if (@$redis->connect($Service->getHost(), $Service->getPort())) {
$ret = true;
}
} catch (\Exception $e) {
}
unset($redis);
return $ret;
break;
} }
} }