Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

redis

laravel

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.

like image 529
Gammer Avatar asked Jul 27 '16 05:07

Gammer


3 Answers

I had this issue in Ubuntu 18.04

I installed redis in my local system, got solved.

sudo apt-get install redis-server
like image 137
Shreekanth Avatar answered Oct 19 '22 12:10

Shreekanth


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.

like image 28
lps Avatar answered Oct 19 '22 14:10

lps


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

like image 3
flik Avatar answered Oct 19 '22 13:10

flik