*
Showing
4 changed files
with
97 additions
and
1 deletions
app/Console/Commands/DealSongIp.php
0 → 100644
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 | /** | ... | ... |
app/Models/Legal/Company.php
0 → 100644
... | @@ -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 | ]; | ... | ... |
-
Please register or sign in to post a comment