Lumen-framework: Can't connect to redis

Created on 17 May 2016  路  13Comments  路  Source: laravel/lumen-framework

Hi, this is my first time to use lumen, and version is 5.2
I want to connect to redis, and I have already installed these softwares in my Macbook

  • Apache/2.4.18 (Unix)
  • PHP 7.0.6
  • PHP70-redis extension

Then I got this problem.

FatalThrowableError in Database.php line 25: Type error: Argument 1 passed to Illuminate\Redis\Database::__construct() must be of the type array, null given, called in ./vendor/illuminate/redis/RedisServiceProvider.php on line 24

in Database.php line 25
at Database->__construct(null) in RedisServiceProvider.php line 24
at RedisServiceProvider->Illuminate\Redis\{closure}(object(Application), array()) in Container.php line 735
at Container->build(object(Closure), array()) in Container.php line 633
at Container->make('redis', array()) in Application.php line 205
at Application->make('redis') in Container.php line 1178
at Container->offsetGet('redis') in CacheManager.php line 187
at CacheManager->createRedisDriver(array('driver' => 'redis', 'connection' => 'default')) in CacheManager.php line 102
at CacheManager->resolve('redis') in CacheManager.php line 77
at CacheManager->get('redis') in CacheManager.php line 55
at CacheManager->store() in CacheManager.php line 296
at CacheManager->__call('forever', array('test2', 'test')) in Facade.php line 221
at Facade::__callStatic('forever', array('test2', 'test')) in ExampleController.php line 21
at ExampleController->test()
at call_user_func_array(array(object(ExampleController), 'test'), array()) in Container.php line 507
at Container->call(array(object(ExampleController), 'test'), array()) in RoutesRequests.php line 586
at Application->callControllerCallable(array(object(ExampleController), 'test'), array()) in RoutesRequests.php line 552
at Application->callLumenController(object(ExampleController), 'test', array(true, array('uses' => 'App\Http\Controllers\ExampleController@test'), array())) in RoutesRequests.php line 526
at Application->callControllerAction(array(true, array('uses' => 'App\Http\Controllers\ExampleController@test'), array())) in RoutesRequests.php line 494
at Application->callActionOnArrayBasedRoute(array(true, array('uses' => 'App\Http\Controllers\ExampleController@test'), array())) in RoutesRequests.php line 479
at Application->handleFoundRoute(array(true, array('uses' => 'App\Http\Controllers\ExampleController@test'), array())) in RoutesRequests.php line 376
at Application->Laravel\Lumen\Concerns\{closure}() in RoutesRequests.php line 629
at Application->sendThroughPipeline(array(), object(Closure)) in RoutesRequests.php line 382
at Application->dispatch(null) in RoutesRequests.php line 327
at Application->run() in index.php line 28

I've also installed predis by using composer, but it didn't work.

Also, I found that it seems like to be an invalid path in file ./vendor/illuminate/cache/RedisStore.php
use Illuminate\Redis\Database as Redis;
the Redis directory do not exists....

What should I do ?

Most helpful comment

I do have $app->register(Illuminate\Redis\RedisServiceProvider::class); in my bootstrap/app.php. when I open this issue
I spent haft day in solving this problem and finally success.

I need to add these config code in the bootstrap/app.php:
config(['database.redis'=> [ 'cluster' => env('REDIS_CLUSTER', false), 'default' => [ 'host' => env('REDIS_HOST', '127.0.0.1'), 'port' => env('REDIS_PORT', 6379), 'database' => env('REDIS_DATABASE', 0), 'password' => env('REDIS_PASSWORD', null), ], ]]);
and it works now

All 13 comments

Make sure $app->register(Illuminate\Redis\RedisServiceProvider::class); is in bootstrap/app.php.

For example:

image

I do have $app->register(Illuminate\Redis\RedisServiceProvider::class); in my bootstrap/app.php. when I open this issue
I spent haft day in solving this problem and finally success.

I need to add these config code in the bootstrap/app.php:
config(['database.redis'=> [ 'cluster' => env('REDIS_CLUSTER', false), 'default' => [ 'host' => env('REDIS_HOST', '127.0.0.1'), 'port' => env('REDIS_PORT', 6379), 'database' => env('REDIS_DATABASE', 0), 'password' => env('REDIS_PASSWORD', null), ], ]]);
and it works now

Looks like you didn't set up the redis.php config correctly.

@GrahamCampbell I wonder where the redis.php config in Lumen is? There is no configs folder in Lumen.

@starit You have to create the folder in the app and copy any configs you need to modify from the framework package into it.

thanks. @Garbee

@starit can you tell me how to do ? thank very much

@ooing copy files from vendor/laravel/lumen-framework/config/database.php and redis.php to your app/config, then replace the config value.
Also, config this code in bootstrap/app.php
$app->configure('database'); $app->configure('cache');

@amlun thanks

I wanted to use Redis for queues and needed to add $app->configure('database'); in bootstrap/app.php to make it work (after added everything that the docs says).

The reason for this is that in RedisServiceProvider.php, Lumen resolves the config for the database to pass to the RedisManager class. If Lumen is not configured to work with a database, then the config will be NULL and it won't work.

https://github.com/laravel/lumen-framework/issues/414#issuecomment-219657373 <--- This should be added to the docs. There are no info about adding the redis section to DB config.

Yup @viirre is right, $app->configure('database'); is missing in the docs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

concept47 picture concept47  路  3Comments

maglor picture maglor  路  3Comments

rmblstrp picture rmblstrp  路  5Comments

jampack picture jampack  路  3Comments

cvinothkumar picture cvinothkumar  路  3Comments