Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No connection could be made because the target machine actively refused it. [tcp://127.0.0.1:6379] on localhost using laravel 5.2

Tags:

laravel-5

I am using Laravel 5.2 and developing an admin panel and trying to integrate Redis 1.0 in Laravel.

When I am trying to set the variable name along with value it prompting an error:

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

The configurational changes i made it is given below:

  • In config/session.php file i replaced file with redis
  • ('driver' => env('SESSION_DRIVER', 'redis'))
  • Under aliases array in config/app.php file the Redis facade is already included 'Redis' => Illuminate\Support\Facades\Redis::class
  • In .env file I replaced file with redis in SESSION_DRIVER variable
  • In database.php file the config for redis server is given below:
'redis' => [
    'cluster' => true,
    'default' => [
        'host' => env('REDIS_HOST', 'localhost'),
        'password' => env('REDIS_PASSWORD', null),
        'port' => env('REDIS_PORT', 6379),
        'database' => 0,
    ],
]

Below is my Controller code:

<?php

namespace App\Http\Controllers\Administrator;

use Redis;
use App\Http\Requests;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class MyController extends Controller
{
    public function __construct() {}

    public function myProfile(Request $request)
    {
        $redis = Redis::connection();
        $adminName = $request->route('admin_name');
        if ($redis) {
            echo 'connection done';
        } else {
            echo 'connection not done';
        }
        Redis::set('name', $adminName);
        echo $redis->get('name');
    }
}

Please help if anyone have an idea of it.

like image 438
saurabh kackar Avatar asked May 20 '16 07:05

saurabh kackar


People also ask

How do you fix no connection could be made because the target machine actively refused it connection failed?

You can try below solution: You might have a firewall rule in the way, or are trying to run it through a proxy without having the proxy up and running. The easiest way to check would be to disable your firewall or proxy and try again. Disable proxy at web.

Could not connect because the target machine actively refused it?

No connection could be made because the target machine actively refused it. This error is a network-related error occurred while establishing a connection to the Server. It means that the error is occurring because there is no server listening at the hostname and port you assigned.

Could not connect to Redis at localhost 6379 no connection could be made because the target machine actively refused it?

Firewall restriction is another common reason that can trigger the “could not connect to Redis connection refused”. By default Redis server listen to the TCP port 6379. If another application is using the port or if the firewall restrictions blocks the port, it can trigger the connection refused error.


1 Answers

I think you are not started the Redis server that's why this error is coming.

Just download and install the Redis server For download the sever just redis server install

For windows 64 go here https://github.com/MicrosoftArchive/redis/releases and
=>Download Redis-x64-3.2.100.msi file
=>Run it and install it
=>Then open the Redis folder (it will the installed folder) then run "redis-server.exe" file.
=>Now your Redis server is activated
=>You can check this by run "redis-cli.exe" file and type ping it will be pong.

like image 55
Bibhudatta Sahoo Avatar answered Oct 26 '22 13:10

Bibhudatta Sahoo