Exemple #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>');
 }
Exemple #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>');
     }
     $stats = (object) array_values($memcached->getStats())[0];
     $output->writeln('Memcached Server Stats');
     $output->writeln('Version: <info>' . $stats->version . '</info>');
     $output->writeln('Uptime: <info>' . timeAgoInWords(date('c', time() - $stats->uptime)) . '</info>');
     $output->writeln('Items in cache: <info>' . $stats->curr_items . '</info>');
     $output->writeln('Size of cache: <info>' . Units::bytes($stats->bytes)->format() . '</info>');
 }
Exemple #3
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>');
     }
 }