laravel / lumen-framework

The Laravel Lumen Framework.
https://lumen.laravel.com
MIT License
1.48k stars 419 forks source link

Can't connect to redis #414

Closed starit closed 8 years ago

starit commented 8 years ago

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

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 ?

GrahamCampbell commented 8 years ago

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

GrahamCampbell commented 8 years ago

For example:

image

starit commented 8 years ago

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

GrahamCampbell commented 8 years ago

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

starit commented 8 years ago

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

Garbee commented 8 years ago

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

starit commented 8 years ago

thanks. @Garbee

ooing commented 7 years ago

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

amlun commented 7 years ago

@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');

ooing commented 7 years ago

@amlun thanks

viirre commented 6 years ago

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.

ingria commented 5 years ago

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.

ptasker commented 5 years ago

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