Example #1
0
 /**
  * Execute the command.
  *
  * @param  InputInterface $input
  * @param  OutputInterface $output
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $memcached = Connection::get($input->getOption('host'), $input->getOption('port'));
     if (!$memcached) {
         return $output->writeln('<error>Could not connect to memcached server!</error>');
     }
     if ($input->getOption('selector')) {
         $regex = Selector::toRegex($input->getOption('selector'));
     } else {
         if ($input->getOption('regex')) {
             $regex = $input->getOption('regex');
         } else {
             $regex = false;
         }
     }
     if ($regex) {
         $output->writeln('<info>All keys matching ' . $regex . '</info>');
     } else {
         $output->writeln('<info>All keys in memcache store</info>');
     }
     $keys = static::keys($memcached, $regex);
     foreach ($keys as $key) {
         $output->writeln('Key: ' . $key);
     }
     $output->writeln('<info>Total keys: ' . count($keys) . '</info>');
 }
Example #2
0
 /**
  * Execute the command.
  *
  * @param  InputInterface $input
  * @param  OutputInterface $output
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $memcached = Connection::get($input->getOption('host'), $input->getOption('port'));
     if (!$memcached) {
         return $output->writeln('<error>Could not connect to memcached server!</error>');
     }
     if ($input->getOption('selector')) {
         $regex = Selector::toRegex($input->getOption('selector'));
     } else {
         if ($input->getOption('regex')) {
             $regex = $input->getOption('regex');
         } else {
             $regex = false;
         }
     }
     if ($input->getOption('key')) {
         $output->writeln('<error>Deleted</error> ' . $input->getOption('key') . ' key');
         $memcached->delete($input->getOption('key'));
     }
     if ($input->getOption('all')) {
         // Not using $memcached->flush(); because keys will still be returned in getAllKeys()
         $output->writeln('<error>Delete</error> all keys in memcache store');
         $keys = Keys::keys($memcached);
         foreach ($keys as $key) {
             $memcached->delete($key);
             $output->writeln('<error>Deleted</error> ' . $key . ' key');
         }
         $output->writeln('<info>' . count($keys) . ' keys deleted</info>');
     }
     if ($regex) {
         $output->writeln('<info>Delete keys matching ' . $regex . '</info>');
         $keys = Keys::keys($memcached, $regex);
         foreach ($keys as $key) {
             $memcached->delete($key);
             $output->writeln('<error>Deleted</error> ' . $key . ' key');
         }
         $output->writeln('<info>' . count($keys) . ' keys deleted</info>');
     }
     if (!$input->getOption('key') && !$input->getOption('all') && !$regex) {
         $output->writeln('For help run <info>memcachedtool help delete</info>');
     }
 }