Gammer
Gammer

Reputation: 5628

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

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.

Upvotes: 27

Views: 82820

Answers (7)

Ani
Ani

Reputation: 561

  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

Upvotes: 0

Roman Slisarenko
Roman Slisarenko

Reputation: 420

A solution for macbook pro on M1:
Replace:

REDIS_HOST=127.0.0.1

with:

REDIS_HOST=host.docker.internal

Upvotes: 7

Hassan Elshazly Eida
Hassan Elshazly Eida

Reputation: 859

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

Upvotes: 1

Abdelsalam Megahed
Abdelsalam Megahed

Reputation: 1501

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.

Upvotes: -1

Shreekanth
Shreekanth

Reputation: 859

I had this issue in Ubuntu 18.04

I installed redis in my local system, got solved.

sudo apt-get install redis-server

Upvotes: 25

flik
flik

Reputation: 3643

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

Upvotes: 3

lps
lps

Reputation: 1408

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.

Upvotes: 11

Related Questions