RedisCommand.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace StatsBundle\Command;
  3. use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
  4. use Symfony\Component\Console\Input\InputInterface;
  5. use Symfony\Component\Console\Input\InputOption;
  6. use Symfony\Component\Console\Output\OutputInterface;
  7. use RedisBundle\Services\RedisService;
  8. class RedisCommand extends BaseCommand
  9. {
  10. protected function configure()
  11. {
  12. $this
  13. ->setName('redis:read')
  14. ->setDescription('Read Redis data')
  15. ->setHelp('This command allows test redis')
  16. ->setDefinition(array(
  17. new InputOption('key', null, InputOption::VALUE_OPTIONAL, "Key redis", null)
  18. ))
  19. ;
  20. }
  21. /**
  22. * @param InputInterface $input
  23. * @param OutputInterface $output
  24. */
  25. protected function execute(InputInterface $input, OutputInterface $output)
  26. {
  27. parent::execute($input, $output);
  28. $key = $input->getOption('key');
  29. if(is_null($key)) {
  30. $this->output->writeln("key es nulo.");
  31. return true;
  32. }
  33. $data = $this->getData($key, true);
  34. if(empty($data)) {
  35. $this->output->writeln("Se requiere {$key}.");
  36. return true;
  37. }
  38. print_r(PHP_EOL."######################".PHP_EOL);
  39. print_r($data);
  40. print_r(PHP_EOL."######################".PHP_EOL);
  41. }
  42. }