I used redis for task queue in laravel, i want to use connection name per queue to handle config varibales conflict in queue in below code :
php artisan queue:work connection-name --deamon --queue=high,medium,low --sleep=3 --tries=3
But i dont know what is the connection name in below code to use:
'default' => env('QUEUE_DRIVER', 'redis'),
'connections' => [
'sync' => [
'driver' => 'sync',
],
'database' => [
'driver' => 'database',
'table' => 'jobs',
'queue' => 'default',
'expire' => 60,
],
'beanstalkd' => [
'driver' => 'beanstalkd',
'host' => 'localhost',
'queue' => 'default',
'ttr' => 60,
],
'sqs' => [
'driver' => 'sqs',
'key' => 'your-public-key',
'secret' => 'your-secret-key',
'prefix' => 'https://sqs.us-east-1.amazonaws.com/your-account-id',
'queue' => 'your-queue-name',
'region' => 'us-east-1',
],
'redis' => [
'driver' => 'redis',
'connection' => 'default',
'queue' => 'default',
'expire' => 60,
],
],
You have several connections configured.
Each connection is an element in the connections array and you just need to pass the relevant key as the name.
e.g.
php artisan queue:work sqs --daemon --queue=high --sleep=3 --tries=3
Related
On Heroku, I'm running Laravel 8. For background activities, I'm utilizing the Laravel Queue. Everything worked OK before, but now I'm getting an error:
The [database] queue connection is not configured
My queue configurations
return [
'default' => env('QUEUE_DRIVER', 'database'),
'connections' => [
'sync' => [
'driver' => 'sync',
],
'database' => [
'driver' => 'database',
'table' => 'jobs',
'queue' => 'default',
'retry_after' => 700,
'after_commit' => false,
'timeout' => 180,
],
I have run composer dump and I have cleared all application cache but it's not working, how can I fix this?
I tried to implement Horizon, from the terminal when I run commands like php artisan horizon:status or php artisan horizon:list I get positive feedbacks, everything seems to work just fine, but when I try to go to the /horizon view, no matter how many jobs I tried to run, in the dashboard I get this.
If I open the console from the browser I get Failed to load resource: the server responded with a status of 500 (Internal Server Error) on all the API calls like api/masters, api/stats or api/workload.
Searching online I found a lot of people saying to fix the .env file or the configuration files like queue.php or horizon.php, but after following their instructions my problem persists
.env:
CACHE_DRIVER=file
QUEUE_CONNECTION=redis
SESSION_DRIVER=file
SESSION_LIFETIME=120
APP_ENV=local
APP_DEBUG=true
LOG_CHANNEL=stack
DB_CONNECTION=mysql
# Redis
REDIS_CLIENT=predis
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
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' => [
'driver' => env('QUEUE_FAILED_DRIVER', 'database'),
'database' => env('DB_CONNECTION', 'mysql'),
'table' => 'failed_jobs',
],
];
horizon.php:
<?php
use Illuminate\Support\Str;
return [
'domain' => env('HORIZON_DOMAIN'),
'path' => env('HORIZON_PATH', 'horizon'),
'use' => 'default',
'prefix' => env(
'HORIZON_PREFIX',
Str::slug(env('APP_NAME', 'laravel'), '_').'_horizon:'
),
'middleware' => ['web'],
'waits' => [
'redis:default' => 60,
],
'trim' => [
'recent' => 60,
'pending' => 60,
'completed' => 60,
'recent_failed' => 10080,
'failed' => 10080,
'monitored' => 10080,
],
'metrics' => [
'trim_snapshots' => [
'job' => 24,
'queue' => 24,
],
],
'fast_termination' => false,
'memory_limit' => 64,
'defaults' => [
'supervisor-1' => [
'connection' => 'redis',
'queue' => ['default'],
'balance' => 'auto',
'maxProcesses' => 1,
'maxTime' => 0,
'maxJobs' => 0,
'memory' => 128,
'tries' => 1,
'timeout' => 60,
'nice' => 0,
],
],
'environments' => [
'production' => [
'supervisor-1' => [
'maxProcesses' => 10,
'balanceMaxShift' => 1,
'balanceCooldown' => 3,
],
],
'local' => [
'supervisor-1' => [
'maxProcesses' => 3,
],
],
],
];
I've setup a redis cluster with 6 nodes locally on my ubuntu 18.04, starting from 127.0.0.1:7000 to 127.0.0.1:7006, with the default 'utils/create-cluster' script that comes with redis binaries.
I'm having issues setting up redis on a laravel 5.7 application, I'm trying to make a request to an endpoint and I'm getting the following error
No connections available in the pool at line 337
myApp/vendor/predis/predis/src/Connection/Aggregate/RedisCluster.php
It's exactly the same error from here --> Predis with laravel 5.5 "No connections available in the pool in Aggregate/RedisCluster.php:337 "
But that answer has not solved my issue, nor the referred link --> https://github.com/nrk/predis/issues/480
My .env file has the following values
BROADCAST_DRIVER=log
CACHE_DRIVER=redis
QUEUE_CONNECTION=sync
SESSION_DRIVER=redis
SESSION_LIFETIME=120
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=7000
And my app/database.php is as follows
'redis' => [
'client' => 'predis',
'cluster' => true,
'options' => [
'cluster' => 'redis',
],
'clusters' => [
'default' => [
[
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => env('REDIS_DB', 0),
],
],
'cache' => [
[
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => env('REDIS_CACHE_DB', 1),
],
]
],
],
I'd appreciate some help!
After a lot of googling and trial and error, I managed to solve the problem by changing the file config/cache.php at the following lines
error:
'redis' => [
'driver' => 'redis'
'connection' => 'cache'
]
working:
'redis' => [
'driver' => 'redis'
'connection' => 'default'
]
I am trying to use redis for caching in laravel.
I have install redis locally and I know it is working as I am able to run horizon queues and workers.
I also get a response when doing
redis-cli PING
but when I try this code
$user = Cache::get('User:' .$Id , function ($Id) {
return User::where('id', '=', $Id)->firstOrFail();
});
I get the error
Redis connection [cache] not configured.
I have changed my .env to have the following entry
CACHE_DRIVER=redis
Find this in cache.php
'redis' => [
'driver' => 'redis',
'connection' => 'cache',
],
and change it to:
'redis' => [
'driver' => 'redis',
'connection' => 'default',
],
can u set redis configration in config/database.php like this
'redis' => [
'client' => 'predis',
'default' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', 'footbar'), //if password otherwise set null
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],
],
other wise set in .env file
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
then run artisan command
php artisan config:cache
php artisan config:clear
step 1 : Configuration : config/database.php add below array
'redis' => array(
'cluster' => false,
'default' => array(
'host' => env('REDIS_HOST', 'localhost'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => env(‘REDIS_DATABASE',0),
),
),
Step 2 : Configuration : .env file
CACHE_DRIVER=redis
REDIS_DATABASE=0
Step 3 : Config/cache.php
'redis' => [
'driver' => 'redis',
'connection' => 'default',
],
Additionally to other answer and in case that you use the redis as queue driver, verify that redis connection is set to "default" in the queue.phpconfiguration file.
What does the 'queue' => 'default' setting do at config/queue.php?
It seems like it does not affect anything.
In config/queue.php my queue configuration is ga-fetcher-queue.
This is my config:
return [
'default' => 'redis',
'connections' => [
'redis' => [
'driver' => 'redis',
'connection' => 'default',
'queue' => 'ga-fetcher-queue',
'retry_after' => 360,
],
],
'failed' => []
];
My redis config at config/database.php is this:
'redis' => [
'client' => 'predis',
'default' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],
]