| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 | <?phpnamespace App\Console\Commands\Recommend;use Illuminate\Console\Command;use Redis;use Log;use App\Modules\Book\Models\BookConfig;class UpdateHighQualityBooks extends Command{    /**     * The name and signature of the console command.     *     * @var string     */    protected $signature = 'UpdateHighQualityBooks';    /**     * The console command description.     *     * @var string     */    protected $description = '更新缓存优质书库';    /**     * Create a new command instance.     *     * @return void     */    public function __construct()    {        parent::__construct();    }    /**     * Execute the console command.     *     * @return mixed     */    public function handle()    {        //统一在此脚本中维护缓存        print_r("======更新缓存优质书库 【任务执行开始】=====" . date("y-m-d H:i:s" . "\n"));        Log::info("======更新缓存优质书库 【任务执行开始】=====" . date("y-m-d H:i:s" . "\n"));        $channels = ['男频','女频'];        foreach ($channels as $channel_name)        {            if($channel_name == '女频') $key = 'female_high_reco_books';            if($channel_name == '男频') $key = 'male_high_reco_books';            //recommend_books            $books = BookConfig::getChannelHighRecommendBooks($channel_name);            $_high_reco_books = [];            foreach ($books as $book)            {                $encode_book = json_encode($book);                $_high_reco_books[$book->bid] = $encode_book;                $reco_books[$book->bid] = $encode_book;            }            Redis::del($key);            Redis::hmset($key,$_high_reco_books);        }        print_r("======更新缓存优质书库 【任务执行结束】=====" . date("y-m-d H:i:s" . "\n"));        Log::info("======更新缓存优质书库 【任务执行结束】=====" . date("y-m-d H:i:s" . "\n"));    }}
 |