Commit ebbe4438 ebbe4438e58457ca7cbc0bb6e3af45e346427ea0 by lemon

*

1 parent f925b825
1 <?php
2
3 namespace App\Console\Commands;
4
5 use App\Helper\RedisClient;
6 use App\Models\Legal\Company;
7 use App\Models\Legal\SongsIp;
8 use Illuminate\Console\Command;
9 use Illuminate\Support\Facades\Redis;
10
11 class DealSongIp extends Command
12 {
13 /**
14 * The name and signature of the console command.
15 *
16 * @var string
17 */
18 protected $signature = 'command:name';
19
20 /**
21 * The console command description.
22 *
23 * @var string
24 */
25 protected $description = 'Command description';
26
27 /**
28 * Create a new command instance.
29 *
30 * @return void
31 */
32 public function __construct()
33 {
34 parent::__construct();
35 }
36
37 /**
38 * Execute the console command.
39 *
40 * @return int
41 */
42 public function handle()
43 {
44 $redis = RedisClient::instance('songip');
45 $company_ids = Company::query()->pluck('company_id')->toArray();
46
47 foreach ($company_ids as $company_id) {
48 $key1 = "company:#company_id#:channel:#channel#:month:#month#:songip";
49 $key2 = "company:#company_id#:channel:#channel#:songip";
50
51 $key1 = str_replace(['#company_id#', '#channel#'], [$company_id, 1], $key1);
52 $key2 = str_replace(['#company_id#', '#channel#'], [$company_id, 1], $key2);
53
54 $redis->del($key1);
55 $redis->del($key2);
56 }
57
58
59 SongsIp::query()->chunk(5000, function ($res) use ($redis) {
60 foreach ($res as $item) {
61 $key = "company:#company_id#:channel:#channel#:month:#month#:songip";
62 $key = str_replace(['#company_id#', '#channel#'], [$item->company_id, 1], $key);
63 $redis->sadd($key, $item->custom_id);
64 }
65 });
66
67
68
69 }
70 }
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
2 2
3 namespace App\Console; 3 namespace App\Console;
4 4
5 use App\Console\Commands\DealSongIp;
5 use Illuminate\Console\Scheduling\Schedule; 6 use Illuminate\Console\Scheduling\Schedule;
6 use Illuminate\Foundation\Console\Kernel as ConsoleKernel; 7 use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
7 8
...@@ -13,7 +14,7 @@ class Kernel extends ConsoleKernel ...@@ -13,7 +14,7 @@ class Kernel extends ConsoleKernel
13 * @var array 14 * @var array
14 */ 15 */
15 protected $commands = [ 16 protected $commands = [
16 // 17 DealSongIp::class,
17 ]; 18 ];
18 19
19 /** 20 /**
......
1 <?php
2
3 namespace App\Models\Legal;
4
5 use App\Models\BaseModel;
6 use Illuminate\Database\Eloquent\SoftDeletes;
7
8 class Company extends BaseModel
9 {
10 use SoftDeletes;
11
12 protected $table = 'company';
13 protected $primaryKey = 'company_id';
14
15 protected $guarded = [];
16
17 }
...@@ -161,6 +161,14 @@ return [ ...@@ -161,6 +161,14 @@ return [
161 'database' => env('REDIS_CACHE_DB', '1'), 161 'database' => env('REDIS_CACHE_DB', '1'),
162 ], 162 ],
163 163
164 'songip' => [
165 'url' => env('REDIS_URL'),
166 'host' => env('REDIS_HOST', '127.0.0.1'),
167 'password' => env('REDIS_PASSWORD', null),
168 'port' => env('REDIS_PORT', '6379'),
169 'database' => 0,
170 ]
171
164 ], 172 ],
165 173
166 ]; 174 ];
......