setName('SsdbUserHasPayKeyFormat') ->setDescription('将原有首充取消标记位haspay转为HP,从分组0拆分一个大hash,到分组1为多个小hash'); } protected function execute(Input $input, Output $output) { Request::instance()->module('admin'); $this->_output = $output; try { $this->logInfo('首充取消标记位haspay转为HP--begin'); $ssdb = Ssdb::instance(); $batchIndex = 0; $oldKey = 'haspay'; 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 => $haspay) { $this->logInfo(sprintf('%s userId:%s,haspay:%s,', date('Y-m-d H:i:s'), $userId, $haspay)); $ignoreUserIdKey = User::getUserHasPayKey($userId); if (!$ssdb->hexists($ignoreUserIdKey, $userId)) { $ssdb->hset($ignoreUserIdKey, $userId, $haspay); } $ssdb->hdel($oldKey, $userId); } } $this->logInfo('首充取消标记位haspay转为HP--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); } }