I have a queue and inside it I want to save some data into Redis cache. But whenever the jobs dispatched, it always give error Error: Call to a member function connect() on null in D:SoftwarexampphtdocsworkxtendancewebvendorlaravelframeworksrcIlluminateRedisRedisManager.php:110
.
I think this is happened because my configuration isn’t correct, but I don’t have any Idea what’s wrong
My .env
CACHE_DRIVER=redis
FILESYSTEM_DRIVER=local
QUEUE_CONNECTION=database
SESSION_DRIVER=file
SESSION_LIFETIME=120
MEMCACHED_HOST=127.0.0.1
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
REDIS_CLIENT=predis
database.php
'redis' => [
'client' => env('REDIS_CLIENT', 'predis'),
'options' => [
'cluster' => env('REDIS_CLUSTER', 'redis'),
'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_database_'),
],
'default' => [
'url' => env('REDIS_URL'),
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', '6379'),
'database' => env('REDIS_DB', '0'),
],
'cache' => [
'url' => env('REDIS_URL'),
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', '6379'),
'database' => env('REDIS_CACHE_DB', '1'),
],
],
cache.php
'redis' => [
'driver' => 'redis',
'connection' => 'cache',
'lock_connection' => 'default',
],
My job function is simply get all data and save it to redis cache
public function handle()
{
$attendance = Attendance::all();
Redis::set('attendance', $attendance);
}
2
Answers
first, you need to install predis with composer. run below command:
second database.php file that its correct
finally you should go to config/app.php and find bellow code and uncomment this.
First, you need to make sure you have installed redis
In your .env file make sure you have these
Also, you need to uncomment Redis in your config/app.php