Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Class 'Redis' not found in Lumen

Tags:

php

redis

lumen

  • Lumen Version: 6.0
  • PHP Version: 7.2
  • Database Driver & Version: MySql 5.7, Redis

image

Code

use Illuminate\Support\Facades\Redis;

Redis::set($key, $data, 'EX', $expiry);

in app.php

$app->withFacades();
$app->withEloquent();

$app->register(Illuminate\Redis\RedisServiceProvider::class);

$app->configure('database');

Using the above code gives Class 'Redis' not found error. This error occurs only when the below packages are installed.

"illuminate/redis": "^6.5",
"illuminate/mail": "^6.5",
"laravel/lumen-framework": "^6.0",

With below packages which has lower versions it works without any error/issues.

"laravel/lumen-framework": "^5.8.*",
"illuminate/redis": "^5.8",
"illuminate/mail": "^5.8",

So why is it giving error when packages are upgraded.

like image 732
Sharath Avatar asked Dec 08 '22 11:12

Sharath


1 Answers

If you are using Laravel 8, in the database.php file, replace the following line:

'client' => env('REDIS_CLIENT', 'phpredis')

to:

'client' => env('REDIS_CLIENT', 'predis')

then, add the predis dependency with composer:

composer require predis/predis
like image 167
pableiros Avatar answered Dec 09 '22 23:12

pableiros