Into my Laravel project I get this error message:
Predis\Connection\ConnectionException
Connection refused [tcp://redis:6380]
Settings Laravel .env
REDIS_HOST=redis
REDIS_PASSWORD=null
REDIS_PORT=6380
REDIS_CLIENT=predis
I added this to config/database.php
'redis' => [
'client' => env('REDIS_CLIENT', 'phpredis'),
'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', 'redis'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6380),
'database' => env('REDIS_DB', 0),
],
'cache' => [
'url' => env('REDIS_URL'),
'host' => env('REDIS_HOST', 'redis'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6380),
'database' => env('REDIS_CACHE_DB', 1),
],
],
Into laradock .env I changed the redis port
### REDIS #################################################
REDIS_PORT=6380
...
REDIS_STORAGE_SERVER_HOST=redis
REDIS_STORAGE_SERVER_PORT=6379
REDIS_STORAGE_SERVER_DB=0
REDIS_STORAGE_SERVER_PASSWORD=None
REDIS_RESULT_STORAGE_SERVER_HOST=redis
REDIS_RESULT_STORAGE_SERVER_PORT=6379
REDIS_RESULT_STORAGE_SERVER_DB=0
REDIS_RESULT_STORAGE_SERVER_PASSWORD=None
...
REDIS_QUEUE_SERVER_HOST=redis
REDIS_QUEUE_SERVER_PORT=6379
REDIS_QUEUE_SERVER_DB="0"
REDIS_QUEUE_SERVER_PASSWORD=None
...
### REDISWEBUI #########################################
REDIS_WEBUI_USERNAME=laradock
REDIS_WEBUI_PASSWORD=laradock
REDIS_WEBUI_CONNECT_HOST=redis
REDIS_WEBUI_CONNECT_PORT=6379
REDIS_WEBUI_PORT=9987
...
WORKSPACE_INSTALL_PHPREDIS=true
...
PHP_FPM_INSTALL_PHPREDIS=true
I stopped all containers and let run:
docker-compose build --no-cache nginx mysql phpmyadmin redis workspace
Then I opend my laravel website and get this error.
What can I do to solve this problem?
Change port to 6379 in laravel and laradock .env:
REDIS_PORT=6379
And restart server
Related
I am running on docker and nginx and Laravel log keeps giving redis not found error while running.
My Configurations:
file .env:
CACHE_DRIVER=redis
SESSION_DRIVER=redis
MEMCACHED_HOST=127.0.0.1
REDIS_HOST=redis
REDIS_PASSWORD=null
REDIS_PORT=6379
file database.php:
'redis' => [
'client' => env('REDIS_CLIENT', 'phpredis'),
'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'),
],
]
I also installed sudo apt-get install php8.0-redis but still not working.
There are a lot of people asking about this problem but I haven't found a good way to solve this problem. I don't know if there is any way you can make it work as it should or can you turn off redis?
Setup Laravel 8.x cache with AWS Elasticache Redis cluster:
i have tried many configure that i found. but none of them work.
i tried connecting Elasticache Redis cluster from redis-cli, it works with Ping pong.
But not working with laravel: (Error: No connections available in the pool)
And this is my config:
'redis' => [
'cluster' => true,
'client' => env('REDIS_CLIENT', 'predis'),
'options' => [
'cluster' => env('REDIS_CLUSTER', 'redis'),
'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_') . '_database_'),
// 'ssl' => ['verify_peer' => false], => have tried, it not working
/*
'parameters' => [ => have tried, it not working
'scheme' => env('REDIS_SCHEME', 'tcp'),
'host' => env('REDIS_HOST', 'localhost'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
'timeout' => 15,
],
*/
],
'clusters' => [
'default' => [
[
'scheme' => env('REDIS_SCHEME', 'tcp'),
'host' => env('REDIS_HOST', 'localhost'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => env('REDIS_CACHE_DB', 0),
'read_write_timeout' => 30,
],
],
'cache' => [
[
'scheme' => env('REDIS_SCHEME', 'tcp'),
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => env('REDIS_CACHE_DB', 1),
]
],
'options' =>[
'cluster' =>'redis',
]
],
],
I have tried connecting Elasticache with Redis cli in Ec2, and it can connect:
And this is Elasticache Redis information:
This is my .env:
CACHE_DRIVER=redis
REDIS_HOST=xxxxx.xxxxx.clustercfg.xxxxx.cache.amazonaws.com
REDIS_PASSWORD=null
REDIS_PORT=6379
By the way, i connect with Configuration Endpoint (not Primary Endpoint)
and i have install "predis/predis" in composer.json.
I changed a lot of configurations that I found on the Google, but it doesn't work. Please help!!
Thanks for reading.
Solution:
Changed with using **phpredis ** it works:
Install php-redis in server:
sudo yum -y install php-redis
sudo systemctl restart php-fpm.service
Change config:
'redis' => [
'client' => env('REDIS_CLIENT', 'phpredis'),
....
]
Not sure why it doesn't work with predis. Even though the configuration is the same.
Here i am having issue with importing Redis class. I've already imported this class
use Illuminate\Support\Facades\Redis;.
Redis config in .env file
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
REDIS_CLIENT=predis
inside 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' => [
'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'),
],
],
These are all the configuration i used but also i am getting the same issue of "Class 'Redis' not found, A class import is missing".
To use the predis Redis client you must install composer require predis/predis.
The other, more performant option, is to use the phpredis client which requires the redis PHP extension. https://github.com/phpredis/phpredis/blob/develop/INSTALL.markdown
I've setup a redis cluster with 6 nodes locally on my ubuntu 18.04, starting from 127.0.0.1:7000 to 127.0.0.1:7006, with the default 'utils/create-cluster' script that comes with redis binaries.
I'm having issues setting up redis on a laravel 5.7 application, I'm trying to make a request to an endpoint and I'm getting the following error
No connections available in the pool at line 337
myApp/vendor/predis/predis/src/Connection/Aggregate/RedisCluster.php
It's exactly the same error from here --> Predis with laravel 5.5 "No connections available in the pool in Aggregate/RedisCluster.php:337 "
But that answer has not solved my issue, nor the referred link --> https://github.com/nrk/predis/issues/480
My .env file has the following values
BROADCAST_DRIVER=log
CACHE_DRIVER=redis
QUEUE_CONNECTION=sync
SESSION_DRIVER=redis
SESSION_LIFETIME=120
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=7000
And my app/database.php is as follows
'redis' => [
'client' => 'predis',
'cluster' => true,
'options' => [
'cluster' => 'redis',
],
'clusters' => [
'default' => [
[
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => env('REDIS_DB', 0),
],
],
'cache' => [
[
'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'd appreciate some help!
After a lot of googling and trial and error, I managed to solve the problem by changing the file config/cache.php at the following lines
error:
'redis' => [
'driver' => 'redis'
'connection' => 'cache'
]
working:
'redis' => [
'driver' => 'redis'
'connection' => 'default'
]
I am trying to use redis for caching in laravel.
I have install redis locally and I know it is working as I am able to run horizon queues and workers.
I also get a response when doing
redis-cli PING
but when I try this code
$user = Cache::get('User:' .$Id , function ($Id) {
return User::where('id', '=', $Id)->firstOrFail();
});
I get the error
Redis connection [cache] not configured.
I have changed my .env to have the following entry
CACHE_DRIVER=redis
Find this in cache.php
'redis' => [
'driver' => 'redis',
'connection' => 'cache',
],
and change it to:
'redis' => [
'driver' => 'redis',
'connection' => 'default',
],
can u set redis configration in config/database.php like this
'redis' => [
'client' => 'predis',
'default' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', 'footbar'), //if password otherwise set null
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],
],
other wise set in .env file
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
then run artisan command
php artisan config:cache
php artisan config:clear
step 1 : Configuration : config/database.php add below array
'redis' => array(
'cluster' => false,
'default' => array(
'host' => env('REDIS_HOST', 'localhost'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => env(‘REDIS_DATABASE',0),
),
),
Step 2 : Configuration : .env file
CACHE_DRIVER=redis
REDIS_DATABASE=0
Step 3 : Config/cache.php
'redis' => [
'driver' => 'redis',
'connection' => 'default',
],
Additionally to other answer and in case that you use the redis as queue driver, verify that redis connection is set to "default" in the queue.phpconfiguration file.