Laravel : Redis No connection could be made : [tcp://127.0.0.1:6379]
Asked Answered
P

7

26

I have installed redis with laravel by adding "predis/predis":"~1.0",

Then for testing i added the following code :

public function showRedis($id = 1)
   {
      $user = Redis::get('user:profile:'.$id);
      Xdd($user);
   } 

In app/config/database.php i have :

'redis' => [
        'cluster' => false,
        'default' => [
            'host' => env('REDIS_HOST', 'localhost'),
            'password' => env('REDIS_PASSWORD', null),
            'port' => env('REDIS_PORT', 6379),
            'database' => 0,
        ],

    ],

It throws the following error : No connection could be made because the target machine actively refused it. [tcp://127.0.0.1:6379]

I using virtualhost for the project. Using Xampp with windows.

Plateau answered 27/7, 2016 at 5:37 Comment(3)
you've got redis set up correctly, andalso check that you're targeting the correct port?Demirep
Yes everything is good ! I think ! If you need something i can update my question !Plateau
Make sure you're running inside Vagrant instead of on your local machineCartier
W
11

First make sure Redis is actually listening on that port by opening up powershell and typing netstat -aon | more (this command may need to be enabled in features or installed somehow). If it is listening then check your firewall settings. If if not listening then make sure Redis is started and is configured to listen on that port.

It looks like predis/predis is a client library only. See https://packagist.org/packages/predis/predis.

You need to install the Redis server, but it looks like it is not officially supported on Windows. See http://redis.io/download. Per information on that page, it looks like there is a Win64 port for Redis here https://github.com/MSOpenTech/redis.

If it still doesn't work after that then update your question with the new error you see.

Wheelock answered 27/7, 2016 at 5:44 Comment(5)
Yes there isn't 6379 port listening... What should i do !Plateau
Hmmm, from a quick google search it looks like predis/predis is merely a Redis client library. Did you install the Redis server? I updated my answer with more info.Wheelock
Yes i have redis server and installed.Plateau
Apparently it is not running or not listening on that port.. I would make sure I could reach the redis server directly through by using telnet or a redis client...check out fellowtuts.com/php/…. Besides that you'll want to post all the relevant configs and command outputs to get any more help on this. Also note that this issue is getting into systems stuff and may be more suited for the Super User sister site.Wheelock
Perfect Man ! Sounds great !Plateau
R
24

I had this issue in Ubuntu 18.04

I installed redis in my local system, got solved.

sudo apt-get install redis-server
Rosaceous answered 4/7, 2019 at 13:27 Comment(3)
This is the kind of simple verification that few talk about. Thanks!Edina
And run in terminal: redis-serverBasia
yeap. worked also with Ubuntu 20.04.2 LTSPassion
W
11

First make sure Redis is actually listening on that port by opening up powershell and typing netstat -aon | more (this command may need to be enabled in features or installed somehow). If it is listening then check your firewall settings. If if not listening then make sure Redis is started and is configured to listen on that port.

It looks like predis/predis is a client library only. See https://packagist.org/packages/predis/predis.

You need to install the Redis server, but it looks like it is not officially supported on Windows. See http://redis.io/download. Per information on that page, it looks like there is a Win64 port for Redis here https://github.com/MSOpenTech/redis.

If it still doesn't work after that then update your question with the new error you see.

Wheelock answered 27/7, 2016 at 5:44 Comment(5)
Yes there isn't 6379 port listening... What should i do !Plateau
Hmmm, from a quick google search it looks like predis/predis is merely a Redis client library. Did you install the Redis server? I updated my answer with more info.Wheelock
Yes i have redis server and installed.Plateau
Apparently it is not running or not listening on that port.. I would make sure I could reach the redis server directly through by using telnet or a redis client...check out fellowtuts.com/php/…. Besides that you'll want to post all the relevant configs and command outputs to get any more help on this. Also note that this issue is getting into systems stuff and may be more suited for the Super User sister site.Wheelock
Perfect Man ! Sounds great !Plateau
S
7

A solution for macbook pro on M1:
Replace:

REDIS_HOST=127.0.0.1

with:

REDIS_HOST=host.docker.internal
Syck answered 30/5, 2023 at 12:16 Comment(2)
Thank you so much. I've been searching for hours!Antitrades
This worked for me even on my Intel. I am using Laravel with laradockHibbs
C
3

Ref solution: https://rapidsol.blogspot.com/2018/10/php-fatal-error-uncaught.html

It is showing your server is not accepting connections from outside. You need to provide ip of your redis server.

$client = new Predis\Client('tcp://192.168.1.103:6379');
//$client = new Predis\Client();
$client->set('foo', 'bar');
$value = $client->get('foo');
echo $value; exit;

if problem still come then try below steps.

So you need to edit : $sudo vi /usr/local/etc/redis.conf

and find the line bind 127.0.0.1 ::1 and change it to #bind 127.0.0.1 ::1 and then find line protected-mode yes and then change it to protected-mode no

and then restart the redis server

Calvary answered 28/10, 2018 at 16:59 Comment(0)
D
1

If you are using mac try to install it here

check brew is installed

brew --version

install redis-server

brew install redis

run server

redis-server
Drin answered 17/4, 2023 at 2:57 Comment(1)
I have Mac book pro M1, and the above one worked for me. Thanks!Guglielma
D
0
  1. Install redis-server depending your MAC machine.

brew install redis

or 

arch -arm64 brew install redis
  1. Run server  If you want to run it for one time use it 

    redis-server

or if you want to run it as background service

brew services start redis
  1. Test it This command will open redis environment so you can check on your server side

    redis-cli

You will see environment 127.0.0.1:6379. Just write "ping" and you will get result as "PONG". If you get this result it works.

Reference for tutorial

Diphthong answered 16/7, 2023 at 19:25 Comment(0)
N
-1

If you are using Redis, make sure that Redis server is up and running, by default Redis runs on 6379 port.

If you are on local environment when you restart the machine sometimes you might need to restart Redis server as well.

Nucleolar answered 2/11, 2021 at 18:19 Comment(2)
Please elaborate your answer so that others can have the full context.Plateau
Added a better description of the contextNucleolar

© 2022 - 2024 — McMap. All rights reserved.