I'm trying to connect Laravel application to Redis (hosted by DigitalOcean) but without success. I'm getting the following error:
Predis\Connection\ConnectionException
Connection timed out [tls://private-db-redis-ams3-xxxxyyyyzzzz.db.ondigitalocean.com:25061]
Here is how my .env file's looking:
REDIS_HOST=db-redis-ams3-xxxxyyyyzzzz.db.ondigitalocean.com
REDIS_PASSWORD=alfjaslkdfjwlkfjlweh
REDIS_PORT=25061
And here's config/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' => [
'scheme' => 'tls',
'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'),
],
],
I added the IP of the web server inside the Trusted Sources section in DigitalOcean's Redis Server Control Panel but it still doesn't want to connect. I tried almost every solution from Google searches. I'm stuck, every help is greatly appreciated!
Related
I have recently switched to using Redis in cluster mode using AWS ElastiCache and my laravel vapor application has started to throw NotSupportedException: Cannot use 'SCAN' with redis-cluster. crash messages. I'm using predis and here is the code causing this issue:
$keys = Redis::scan(0, 'match', $pattern);
Here is my database.php config for redis:
'redis' => [
'cluster' => true,
'client' => env('REDIS_CLIENT', 'predis'),
'options' => [
'cluster' => env('REDIS_CLUSTER','redis'),
],
'clusters' => [
'sessions' => [
[
'host' => env('SESSIONS_REDIS_HOST', 'redis'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => env('REDIS_CACHE_DB', 1),
]
],
'default' => [
[
'host' => env('REDIS_HOST', 'redis'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => env('REDIS_DB', 0),
]
],
'cache' => [
[
'scheme' => env('REDIS_SCHEME', 'tcp'),
'host' => env('REDIS_HOST', 'redis'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => env('REDIS_CACHE_DB', 1),
]
],
'options' => [
'cluster' => 'redis'
]
]
]
Is there a way I can use scan in cluster mode or a work around to scan all keys without too much performance hit? Thanks
I deploy my php laravel project (version 5.8) in digitalocean. I use remote SQL server for the database. I can connect to remote sql server by SQL SERVER MANAGEMENT, but when i use in laravel, i get this error
"message": "SQLSTATE[HY000] Unable to connect: Adaptive Server is unavailable or does not exist (192.168.x.xxxx:1433) (severity 9) (SQL: select top 1 * from [users] where [email] = )",
here is my .env setting
DB_CONNECTION=sqlsrv
DB_HOST=192.168.0.xxx
DB_PORT=1433
DB_DATABASE=xxxx
DB_USERNAME=xxx
DB_PASSWORD=xxxx
<?php
return [
'default' => env('DB_CONNECTION', 'sqlsrv'),
'connections' => [
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', '192.168.x.xxx'),
'port' => env('DB_PORT', '1433'),
'database' => env('DB_DATABASE', 'xxx'),
'username' => env('DB_USERNAME', 'xxx'),
'password' => env('DB_PASSWORD', 'xxxx'),
'charset' => 'utf8',
'prefix' => '',
],
],
'migrations' => 'migrations',
'redis' => [
'client' => 'predis',
'default' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],
],
];
Try to change
'driver' => 'sqlsrv',
to
'driver' => 'mysql',
I'm trying to setup Redis client to connect to the Redis server in Laravel 6.0 version, but when I try to change the REDIS_HOST in database.php file in config it gives me an error:
Connection refused 127.0.0.1:6379
This is how my code looks like in routes api.php file
Route::get('test',function(Request $request){
$redis=Redis::connection();
$redis->set("key1","keyValue");
$a=$redis->get("key1");
return response()->json( ['test'=>$a,]);
});
and this is how my database.php file looks like
'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),
],
],
So when i change the REDIS_HOST its gives me error,any idea is my code problem the configurations?
Thanks !
I encountered this on my MacBook and fixed it by installing Redis using homebrew as directed here
PS: I'm working with Laravel 8.40
I am trying to use ElasticCache Redis Cluster(Cluster mode enabled not sentinel) on Laravel-5.4.32 but getting below error:
1/1) ServerException
MOVED 13491 10.0.1.199:6379
My database.php looks like below:
'redis' => [
'client' => 'predis',
'cluster' => true,
'default' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],
],
REDIS_HOST value is been provided using .env file.
My application works fine with single redis instance.
Below configuration worked for me:
'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,
],
],
],
],
Actually, this is clearly mentioned in laravel documentation: https://laravel.com/docs/5.4/redis#configuration
I'm running Laravel in a GlusterFS cluster, and I want to setup a redis cluster too. I'm not able to find out how should I configure Laravel.
This is the example config file:
'redis' => [
'cluster' => false,
'default' => [
'host' => env('REDIS_HOST', 'localhost'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],
],
How can I add multiple servers?
I'm assuming you just add another server there and update the cluster boolean:
'redis' => [
'cluster' => true,
'default' => [
'host' => env('REDIS_HOST', 'localhost'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],
'secondary' => [
'host' => '127.0.0.1',
'password' => 'p#ssw0rd',
'port' => 6379,
'database' => 0,
],
],