php Laravel:Redis 无法建立连接:[tcp://127.0.0.1:6379]

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38604524/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 01:39:17  来源:igfitidea点击:

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

phplaravelredis

提问by Gammer

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

我已经通过添加使用 laravel 安装了 redis "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 :

在 app/config/database.php 我有:

'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]

它引发以下错误: No connection could be made because the target machine actively refused it. [tcp://127.0.0.1:6379]

I using virtualhostfor the project. Using Xampp with windows.

virtualhost用于项目。使用Xampp with windows.

采纳答案by lps

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.

首先,通过打开 powershell 并键入netstat -aon | more(此命令可能需要在功能中启用或以某种方式安装),确保 Redis 实际上正在侦听该端口。如果它正在侦听,请检查您的防火墙设置。如果不侦听,则确保 Redis 已启动并配置为侦听该端口。

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

看起来predis/predis只是一个客户端库。请参阅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.

您需要安装Redis服务器,但在Windows上似乎没有正式支持。请参阅http://redis.io/download。根据该页面上的信息,这里的 Redis 似乎有一个 Win64 端口https://github.com/MSOpenTech/redis

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

如果在那之后它仍然不起作用,请使用您看到的新错误更新您的问题。

回答by Shreekanth

I had this issue in Ubuntu 18.04

我在 Ubuntu 18.04 中遇到了这个问题

I installed redis in my local system, got solved.

我在本地系统中安装了redis,解决了。

sudo apt-get install redis-server

回答by flik

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

参考解决方案: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.

它显示您的服务器不接受来自外部的连接。你需要提供你的redis服务器的ip。

$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

所以你需要编辑: $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

并找到行 bind 127.0.0.1 ::1 并将其更改为 #bind 127.0.0.1 ::1 然后找到行 protected-mode yes 然后将其更改为 protected-mode no

and then restart the redis server

然后重启redis服务器