简体   繁体   English

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

[英]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" ,我通过添加"predis/predis":"~1.0" predis "predis/predis":"~1.0" predis "predis/predis":"~1.0"安装了带有 laravel 的 redis,

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] No connection could be made because the target machine actively refused it. [tcp://127.0.0.1:6379]

I using virtualhost for the project.我为项目使用virtualhost Using Xampp with windows .Xampp with windows使用。

First make sure Redis is actually listening on that port by opening up powershell and typing netstat -aon | more 首先确保Redis实际上是通过打开powershell并输入netstat -aon | more来侦听该端口 netstat -aon | more (this command may need to be enabled in features or installed somehow). netstat -aon | more (此命令可能需要在功能中启用或以某种方式安装)。 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. 如果没有监听,请确保Redis已启动并配置为侦听该端口。

It looks like predis/predis is a client library only. 看起来predis/predis只是一个客户端库。 See https://packagist.org/packages/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. 您需要安装Redis服务器,但看起来它在Windows上不受官方支持。 See http://redis.io/download . 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的Win64端口位于https://github.com/MSOpenTech/redis

If it still doesn't work after that then update your question with the new error you see. 如果在此之后它仍无效,请使用您看到的新错误更新您的问题。

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 并找到行绑定127.0.0.1 :: 1并将其更改为#bind 127.0.0.1 :: 1然后找到行protected-mode yes然后将其更改为protected-mode no

and then restart the redis server 然后重新启动redis服务器

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

如果您使用的是 Redis,请确保Redis 服务器正在运行,默认情况下在此 6379 端口上

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 连接被拒绝 [tcp://127.0.0.1:6379] Laravel Predis - Connection refused [tcp://127.0.0.1:6379] Laravel Predis 在 linux 服务器上使用 redis 连接超时 [tcp://127.0.0.1:6379] - Connection timed out [tcp://127.0.0.1:6379] using redis on linux server Laravel 通过 Redis 排队:local.ERROR:连接到 127.0.0.1:6379 时出现读取错误 - Laravel Queue via Redis: local.ERROR: read error on connection to 127.0.0.1:6379 Redis 向服务器写入字节时出错。 [tcp://127.0.0.1:6379] - Redis Error while writing bytes to the server. [tcp://127.0.0.1:6379] 连接被拒绝[tcp:// IP-ADDRESS-HERE:6379] Redis。 Laravel - Connection refused [tcp://IP-ADDRESS-HERE:6379] Redis. Laravel php_network_getaddresses:getaddrinfo 失败:不知道这样的主机。 [tcp://redis:6379] 在 laravel - php_network_getaddresses: getaddrinfo failed: No such host is known. [tcp://redis:6379] in laravel 名称或服务未知 [tcp://redis:6379] - Name or service not known [tcp://redis:6379] sqlsrv_connect 工作正常,但 laravel 失败并显示:TCP 提供程序:无法建立连接,因为目标计算机主动拒绝它 - sqlsrv_connect works fine but laravel fails with : TCP Provider: No connection could be made because the target machine actively refused it 无法建立连接,因为目标计算机主动拒绝了它的LARAVEL 4错误 - No connection could be made because the target machine actively refused it LARAVEL 4 error 无法建立连接,因为目标计算机主动拒绝了它Laravel 5 - No connection could be made because the target machine actively refused it Laravel 5
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM