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); $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>"); } } }