Laravel Redis configuration - php

I am currently creating an app with Laravel and Redis. Almost everything is working fine. I extended the Authentication as explained in the documentation, users can subscribe, login, logout ... I can create content and everything is stored in Redis.
But I have one issue. I can't run commands like "php artisan route:list", I have an error message : "[InvalidArgumentException] Database [redis] not configured.".
Th question is, is there anything special to do to make Artisan commands work when you set Redis as you database ? (basic configurations explained in the documention have been done and almost everything else is working fine).
Config:
In config/database.php I have:
return [
...
'default' => 'redis',
...
'redis' => [
'cluster' => false,
//'connection' => 'default',
'default' => [
'host' => '127.0.0.1',
'port' => 6379,
'database' => 7,
],
],
...
PS : You have the same error when you try to access the /password/email (password reset url).
InvalidArgumentException in DatabaseManager.php line 246:
Database [redis] not configured.

As Robert says in the comments, it looks like there is this error because there is no support for Redis as database for laravel.

Related

Call to undefined method Illuminate\Support\Facades\Redis::connect()

Running Laravel 5.7 via Homestead.
This is happening in:
/vendor/laravel/framework/src/Illuminate/Redis/Connectors/PhpRedisConnector.php
"line":66
"function":"establishConnection"
We are using PHP Redis and in config/database.php:
'redis' => [
'client' => 'phpredis',
'default' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 6,
],
],
I've seen other answers on here and none of the steps work. There is no redis cluster in use. PhpRedis extension is installed on VM and confirmed with php -m. Redis server is running at 127.0.0.1 and can be connected to outside of the code.
I'm unable to change the code as it works for others. It must be a configuration issue on my VM but I can't see what it could be. If anyone has had a similar issue I'd much appreciate any advice.
The problem you are having is because of class naming conflict: PhpRedisConnector creates new \Redis client, but it seems that you have alias for Illuminate\Support\Facades\Redis facade set up somewhere in your app. PhpRedisConnector creates new Redis and gets facade object instead.
Try removing this line in your config/app.php:
'aliases' => [
...
'Redis' => Illuminate\Support\Facades\Redis::class, // remove this line
...
]

Laravel phpunit drops database tables

I'm trying to test my app using phpunit with laravel but each time I run
unit test
vendor\bin\phpunit
All tables in my database drop so I have to migrate each time I run a test
Have you encountered with similar issue & how can I fix it ?
Use a separate connection for tests. Add this connection to config/database.php config file:
'connections' => [
'testing' => [
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
],

Elasticache PHP Redis AWS Moved Exception in Laravel

I am using laravel 5.2 and having an architecture of multi-server autoscaling. I want to have session and cache in a centralized location. I want to use AWS elasticache for the same.
I have setup an elasticache Redis cluster having following options :
Parameter group : default.redis.3.2.cluster.on
Shards : 3
Total Nodes : 9
In laravel session configuration I have set redis as the session driver.
In database.php where redis configuration is set, i have used following :
REDIS_HOST=my_aws_elasticache_configuration_endpoint
REDIS_PASSWORD=null
REDIS_PORT=6379
.
When I try to use it, I get following error :
MOVED 13841 some_ip_address_of_aws:6379
I tried using local redis and it worked, so predis is working properly. I tried to check the solutions online, but not able to get the solution. I believe that the configuration endpoint is trying to redirect the redis connection to an available node url out of the 9 nodes I have. However, I have anticipated that AWS should do it internally and not throw exception. Can anyone help me?
I finally got an answer, we need to get the cluster mode on in database settings and set new cluster option to redis. This is how the redis config in database.php looks like :
'redis' => [
'client' => 'predis',
'options' => [
'cluster' => 'redis',
],
'clusters' => [
'default' => [
[
'host' => env('REDIS_HOST', 'localhost'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],
],
],
],
If you have password then you can replace options array with this :
'options' => [
'cluster' => 'redis',
'parameters' => ['password' => env('REDIS_PASSWORD', null)],
],

Laravel 5.2 Mongo MonogDB Failed to parse MongoDB URI

I am getting this error:
MongoDB\Driver\Exception\InvalidArgumentException: Failed to parse MongoDB URI: 'mongodb://mongo:tcp://172.17.0.3:27017/mydatabase' in /var/www/laravel/vendor/mongodb/mongodb/src/Client.php:81
My enviroment variables look like this:
MONGO_DATABASE="mydatabase"
MONGO_HOST="mongo"
MONGO_PASSWORD=""
MONGO_PORT="27017"
MONGO_USERNAME=""
and my database.php looks like this
'mongodb' => [
'driver' => 'mongodb',
'host' => env('MONGO_HOST', 'localhost'),
'port' => env('MONGO_PORT', 27017),
'database' => env('MONGO_DATABASE', 'mydatabase'),
'username' => env('MONGO_USERNAME', ''),
'password' => env('MONGO_PASSWORD', ''),
'options' => [
'database' => 'admin' // sets the authentication database required by mongo 3
]
I can correctly ping mongo from the container and it resolves to 172.17.0.3 as per the connection string. It seems as if the rest of the connection string is not getting generated correct?
I am running Laravel 5.2 and my package.json has this entry
"mongodb/mongodb": "^1.0.0",
"jenssegers/mongodb": "3.0.*",
As per https://github.com/jenssegers/laravel-mongodb 3.0.X is highest compatibility for Laravel 5.2.
Many thanks in advance
After further investigation my link from Amazon ECS was passing another MONGO_PORT which was overriding the env set in my .env file.

Install of laravel 4 from pagodabox breaks on localhost

How do I get laravel to work on local host from pagodabox? I've installed laravel 4 through pagoda box, then cloned it to localhost. I then ran composer install to get all the dependencies and updates. When I try to navigate the URI to the public directory, it doesn't show me a "you have arrived" screen. Instead I get the following error message:
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. [tcp://tunnel.pagodabox.com:6379]
I then looked in "database.php" and noticed that the redis array was modified, so I copied the same one from a fresh installation of Laravel, but then I got the following error:
No connection could be made because the target machine actively refused it. [tcp://127.0.0.1:6379]
I Had the same problem, just change the bootstrap > start.php file, search for
'local' => array('your-machine-name')
and change it with your machine name.
This video help me to deal with that: http://www.youtube.com/watch?v=CJoU-LO8Ufo , in the video he changes it to the virtual host but that didn't work for me, i had to put my computer name.
On Mac the computer name can be found by typing hostname in the terminal.
Joshdcid's answer is right for some, but not all. I found this in my bootstrap > start.php file:
'local' => array('homestead')
..., and changing that variable in any way caused my laravel app to not load at all. Not only that, but in a fresh install of laravel, this local variable had the same value of 'homestead'.
After spending a bit of time in WinMerge, I found that you should use Wayne's tip of changing
'redis' => array(
'cluster' => false,
'default' => array(
'host' => 'tunnel.pagodabox.com',
'port' => 6379,
'database' => 0,
),
),
to
'redis' => array(
'cluster' => false,
'default' => array(
'host' => '127.0.0.1',
'port' => 6379,
'database' => 0,
),
),
at the bottom of the app > config > database.php file, then you should also go to the top of the
app > config > session.php file and change
'driver' => 'redis',
to
'driver' => 'file',
..., just as a fresh install would have. You should be able to view your app now!

Categories