我设置了所有配置键以使用Redis。运行正常,我进行了测试。 使用以下代码段。
Route::get('/counter',function() {
$counter = Redis::incr('counter');
return $counter;
});
Route::get('/gename',function() {
$redis = Redis::connection();
$redis->set("name","John Doe");
return $redis->get("name");
});
我得到了预期的结果。
我还可以在redis-cli中使用KEYS '*'
来查看设置键。
现在,我正在使用Laravel队列将邮件作业分派到队列。
{
public function sendEmail()
{
$emailJob = (new SendEmailJob())->delay(Carbon::now()->addSeconds(3));
dispatch($emailJob);
echo "email sent";
}
}
如果我没看错,因为queue_connection是redis,它应该为作业设置一些键。但是我在redis-cli中看不到任何设置键。
当我运行任何队列命令时,也会卡住。
php artisan queue:listen
或
php artisan queue:work
.env
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:QBkErBPtVTE9UxdJXNeqlOqm6zrX7qslG5E8d/Yhmtc=
APP_DEBUG=true
APP_URL=http://localhost
LOG_CHANNEL=stack
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=queue
DB_USERNAME=root
DB_PASSWORD=
BROADCAST_DRIVER=log
CACHE_DRIVER=redis
QUEUE_CONNECTION=redis
SESSION_DRIVER=redis
SESSION_LIFETIME=120
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=my_username_I_won't_show_go_get_yours_it's_free
MAIL_PASSWORD=my_password_I_won't_show_go_get_yours_it's_free
MAIL_ENCRYPTION=tls
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
config / queue.php
<?php
return [
'default' => env('QUEUE_CONNECTION', 'redis'),
'connections' => [
'sync' => [
'driver' => 'sync',
],
'database' => [
'driver' => 'database',
'table' => 'jobs',
'queue' => 'default',
'retry_after' => 90,
],
'beanstalkd' => [
'driver' => 'beanstalkd',
'host' => 'localhost',
'queue' => 'default',
'retry_after' => 90,
'block_for' => 0,
],
'sqs' => [
'driver' => 'sqs',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'prefix' => env('SQS_PREFIX', 'https://sqs.us-east-1.amazonaws.com/your-account-id'),
'queue' => env('SQS_QUEUE', 'your-queue-name'),
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
],
'redis' => [
'driver' => 'redis',
'connection' => 'default',
'queue' => env('REDIS_QUEUE', 'default'),
'retry_after' => 90,
'block_for' => null,
],
],
'failed' => [
'database' => env('DB_CONNECTION', 'mysql'),
'table' => 'failed_jobs',
],
];