public function onMessage(ConnectionInterface $from, $msg)
 {
     $memcachedHelper = new MemcachedHelper($this->memcacheAddress, $this->memcachePort);
     if ($this->clients->contains($from)) {
         $msg = json_decode($msg, true);
         $action = isset($msg['action']) && !empty($msg['action']) ? $msg['action'] : '';
         switch ($action) {
             case 'get_memcache_data':
                 $msg['action'] = $action;
                 $msg['data'] = $memcachedHelper->getMemcacheData(null, null, false, true);
                 $data = json_encode($msg);
                 $from->send($data);
                 break;
             case 'get_memcache_key_info':
                 $msg['action'] = $action;
                 $msg['data'] = $memcachedHelper->getMemcacheData(array($msg['key']));
                 $data = json_encode($msg);
                 $from->send($data);
                 break;
             case 'flush_key':
                 $msg['action'] = $action;
                 $msg['data'] = $memcachedHelper->flushMemcacheData(array($msg['key']));
                 $data = json_encode($msg);
                 $from->send($data);
                 break;
             case 'flush_all':
                 $msg['action'] = $action;
                 $msg['data'] = $memcachedHelper->flushMemcacheData();
                 $data = json_encode($msg);
                 $from->send($data);
                 break;
         }
     }
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $memcachedAddress = $input->getOption('address');
     $memcachedPort = $input->getOption('port');
     $memcachedHelper = new MemcachedHelper($memcachedAddress, $memcachedPort);
     if ($input->getOption('count')) {
         $keysCount = $memcachedHelper->getKeysCount();
         $output->writeln("<info>Number of the keys in storage: {$keysCount}</info>");
         return;
     }
     $keys = $input->getArgument('key');
     $compactMode = !empty($keys) && count($keys) <= 3 ? true : false;
     $keysNumber = $input->getOption('number');
     $mcData = $memcachedHelper->getMemcacheData($keys, $keysNumber, $compactMode);
     if ($compactMode && is_array($mcData) && !empty($mcData)) {
         $outputStyle = new OutputFormatterStyle('yellow', null, array('bold'));
         $output->getFormatter()->setStyle('compactInfo', $outputStyle);
         foreach ($mcData as $data) {
             $output->writeln("<compactInfo>Key:</compactInfo> {$data[0]}");
             $output->writeln("");
             $output->writeln("<compactInfo>Value:</compactInfo> {$data[1]}");
             $output->writeln("");
             $output->writeln("<fg=green;options=bold>------------------------------------------</>");
         }
     } elseif (is_array($mcData) && !empty($mcData)) {
         $table = new Table($output);
         $table->setHeaders(['Key', 'Value'])->setRows($mcData);
         $table->render();
     } else {
         $output->writeln("<error>Nothing to show! Check your memcached server.</error>");
     }
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $memcachedAddress = $input->getOption('address');
     $memcachedPort = $input->getOption('port');
     $memcachedHelper = new MemcachedHelper($memcachedAddress, $memcachedPort);
     $flushKeys = $input->getArgument('key');
     if (is_array($flushKeys) && !empty($flushKeys)) {
         $keyNames = implode(', ', $flushKeys);
         $maxStrLen = 30;
         if (strlen($keyNames) > $maxStrLen) {
             $keyNames = substr($keyNames, 0, $maxStrLen) . '...';
         }
         $questionText = "<question>Do you really wanna flush " . "keys - {$keyNames}?  [y/N]</question>";
     } else {
         $questionText = "<question>Do you really wanna flush " . "all memcache keys?  [y/N]</question>";
     }
     $questionHelper = $this->getHelper('question');
     $question = new ConfirmationQuestion($questionText, false);
     $choice = $questionHelper->ask($input, $output, $question);
     if (!$choice) {
         return;
     } else {
         if ($memcachedHelper->flushMemcacheData($flushKeys)) {
             $output->writeln("<info>All keys successfully flushed</info>");
         }
     }
 }