123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- <?php
- namespace app\admin\command;
- use app\common\library\Redis;
- use app\common\service\BookRelationService;
- use think\console\Command;
- use think\console\Input;
- use think\console\input\Argument;
- use think\console\Output;
- use think\Log;
- use think\Request;
- class BookRelationInit extends Command
- {
- /**
- * 配置指令
- */
- protected function configure()
- {
- $this->setName('BookRelationInit');
- }
- protected function execute(Input $input, Output $output)
- {
- Request::instance()->module('admin'); //cli模式下无法获取到当前的项目模块,手动指定一下
- $redis = Redis::instance();
- try {
- $ids = model('book_relation')->field('book_id')->group('book_id')->select();
- if ( empty($ids)){
- Log::info('table: book_relation empty' );
- }
- foreach ($ids as $k => $v) {
- $str = BookRelationService::instance()->getBookRelationById($v['book_id']);
- if ( $redis->Exists( 'B:'.$v['book_id']) ){
- $redis->hSet( 'B:'.$v['book_id'], 'relation_id', $str );
- Log::info('book_relation redis update:'.$v['book_id'].' relations:'.$str );
- }
- }
- } catch (\Throwable $Th) {
- Log::info('error:'.$Th->getMessage());
- }
- Log::info('BookRelationInit over');
- }
- }
|