123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <?php
- namespace App\Console\Commands;
- use Carbon\Carbon;
- use Illuminate\Console\Command;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Redis;
- class LoadBoxNoToRaidsCommand extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'load:box_no_and_bike_no_to_redis';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = '加载车的位置数据到redis中';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- $redis = Redis::connection();
- $this->line('开始加载');
- $redis->del(['box_no_and_bike_no']);
- DB::table('bikes')->select(['box_no', 'bike_no', 'id'])->get()->each(function ($bike) use ($redis) {
- if ($bike->box_no && $bike->bike_no) {
- $this->line($bike->bike_no);
- $redis->hset('box_no_and_bike_no', $bike->box_no, $bike->bike_no);
- }
- });
- $this->line('完成');
- }
- }
|