setName('SsdbIgnoreUserIdKeyFormat') ->setDescription('将原有白名单ignore-user转为IU,从分组0拆分一个大hash,到分组1为多个小hash'); } protected function execute(Input $input, Output $output) { Request::instance()->module('admin'); $this->_output = $output; try { $this->logInfo('用户id白名单转为IU--begin'); $ssdb = Ssdb::instance(); $batchIndex = 0; $oldKey = 'ignore-user'; while (true) { $batchIndex++; $valueList = $ssdb->hscan($oldKey, '', '', 5000); $this->logInfo(sprintf('批次:%s,key数量:%s。', $batchIndex, count($valueList))); if (empty($valueList)) { $this->logInfo('当前批次key数量为0,退出程序'); break; } foreach ($valueList as $userId => $ip) { $this->logInfo(sprintf('%s userId:%s,Ip:%s,', date('Y-m-d H:i:s'), $userId, $ip)); $ignoreUserIdKey = User::getIgnoreUserIdKey($userId); if (!$ssdb->hexists($ignoreUserIdKey, $userId)) { $ssdb->hset($ignoreUserIdKey, $userId, $ip); } $ssdb->hdel($oldKey, $userId); } } $this->logInfo('用户id白名单转为IU--end'); } catch (\Exception $e) { $this->logError(date('Y-m-d H:i:s') . $e->getMessage()); } } /** * @param $msg */ private function logInfo($msg) { Log::info($msg); $this->_output->writeln($msg); } /** * @param $msg */ private function logError($msg) { Log::error($msg); $this->_output->writeln($msg); } }