laravel中如何优雅的处理redis订阅超时的问题
默认情况下在laravel11中订阅redis频道会超时,代码如下:
<?php
namespace App\Console\Commands;
use App\Jobs\UpdateCallTaskJob;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Redis;
class SubscribeCdrCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:subscribe-cdr-command';
/**
* The console command description.
*
* @var string
*/
protected $description = '订阅呼叫中心通话记录';
/**
* Execute the console command.
*/
public function handle(): void
{
$this->info('开始订阅呼叫中心通话记录');
Redis::subscribe(['cdr'], function ($message) {
$data = json_decode($message, true);
$uuid = $data['uuid'] ?? null;
$task_id = $data['task_id'] ?? null;
$this->info('已经订阅到消息');
if ($uuid && $task_id) {
$this->info('开始处理消息');
UpdateCallTaskJob::dispatch($uuid, $task_id);
}
});
}
}
设置了config/database.php
中read_write_timeout
为0也是会报错:
local.ERROR: read error on connection to 127.0.0.1:6379 {"exception":"[object] (RedisException(code: 0): read error on connection to 127.0.0.1:6379 at /www/wwwroot/callcenter.xxxxx.com/vendor/laravel/framework/src/Illuminate/Redis/Connections/PhpRedisConnection.php:459)
推荐文章: