无法建立连接,因为目标计算机主动拒绝了该连接. [tcp://127.0.0.1:6379]在本地主机上使用laravel 5.2 [英] No connection could be made because the target machine actively refused it. [tcp://127.0.0.1:6379] on localhost using laravel 5.2

查看:1439
本文介绍了无法建立连接,因为目标计算机主动拒绝了该连接. [tcp://127.0.0.1:6379]在本地主机上使用laravel 5.2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Laravel 5.2并开发一个管理面板,并试图将Redis 1.0集成到Laravel中.

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:

无法建立连接,因为目标计算机主动拒绝了该连接. [tcp://127.0.0.1:6379]

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:

  • 在config/session.php文件中,我用redis替换了文件
  • ('driver'=> env('SESSION_DRIVER','redis'))
  • config/app.php文件的aliases数组下,Redis外观已包含在'Redis' => Illuminate\Support\Facades\Redis::class
  • .env文件中,我用SESSION_DRIVER变量中的redis替换了file
  • database.php文件中,redis服务器的配置如下所示:
  • 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.

推荐答案

我认为您没有启动 Redis服务器,这就是为什么会出现此错误.

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

只需下载并安装Redis服务器 要下载服务器,只需 redis服务器安装

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

对于 Windows 64 ,请访问此处 https://github.com/MicrosoftArchive /redis/releases
=>下载 Redis-x64-3.2.100.msi 文件
=>运行并安装
=>然后打开Redis文件夹(它将是已安装的文件夹),然后运行"redis-server.exe"文件.
=>现在您的Redis服务器已激活
=>您可以通过运行"redis-cli.exe"文件并输入ping来检查它.

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.

这篇关于无法建立连接,因为目标计算机主动拒绝了该连接. [tcp://127.0.0.1:6379]在本地主机上使用laravel 5.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆