-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add checker to check availability of redis (#815)
- Loading branch information
Showing
10 changed files
with
125 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace Shopsys\FrameworkBundle\Command; | ||
|
||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class CheckRedisCommand extends Command | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected static $defaultName = 'shopsys:redis:check-availability'; | ||
|
||
/** | ||
* @var \Redis | ||
*/ | ||
protected $cacheClients; | ||
|
||
/** | ||
* @param \Redis[] $cacheClients | ||
*/ | ||
public function __construct(array $cacheClients) | ||
{ | ||
$this->cacheClients = $cacheClients; | ||
|
||
parent::__construct(); | ||
} | ||
|
||
protected function configure() | ||
{ | ||
$this | ||
->setDescription('Checks availability of Redis'); | ||
} | ||
|
||
/** | ||
* @param \Symfony\Component\Console\Input\InputInterface $input | ||
* @param \Symfony\Component\Console\Output\OutputInterface $output | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$output->writeln('Checks availability of Redis...'); | ||
foreach ($this->cacheClients as $cacheClient) { | ||
try { | ||
$cacheClient->ping(); | ||
} catch (\RedisException $e) { | ||
throw new \Shopsys\FrameworkBundle\Command\Exception\RedisNotRunningException('Redis is not available.'); | ||
} | ||
} | ||
$output->writeln('Redis is available'); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
packages/framework/src/Command/Exception/RedisNotRunningException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace Shopsys\FrameworkBundle\Command\Exception; | ||
|
||
use Exception; | ||
use Throwable; | ||
|
||
class RedisNotRunningException extends Exception | ||
{ | ||
/** | ||
* @param string $message | ||
* @param int $code | ||
* @param \Throwable|null $previous | ||
*/ | ||
public function __construct($message = '', $code = 0, Throwable $previous = null) | ||
{ | ||
parent::__construct($message, $code, $previous); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters