【问题标题】:Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSEDRedis 连接到 127.0.0.1:6379 失败 - 连接 ECONNREFUSED
【发布时间】:2012-01-06 06:40:03
【问题描述】:

我通过 expressjs 使用 node.js
我尝试将帐户存储到会话。所以,我尝试使用expressjs中的代码测试使用会话

var RedisStore = require('connect-redis')(express);
app.use(express.bodyParser());
app.use(express.cookieParser());
app.use(express.session({ secret: "keyboard cat", store: new RedisStore }));

但我收到错误 Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED
请帮我解决这个问题

【问题讨论】:

  • Redis 正在运行吗?您可以通过其他方式连接到它吗? redis-cli?
  • 谢谢你,因为 redis 服务器没有运行。我安装 redis-server 关注this tutorial
  • 你应该在你的机器上安装 Redis 服务器并运行它。不知道作者为什么在手册中没有提到这个重要的东西!
  • 如何为我的节点 Heroku 应用添加 redis-server?我也有同样的错误。

标签: javascript node.js express redis econnrefused


【解决方案1】:

安装redis后,在终端输入:

redis-server

你将运行 redis

【讨论】:

  • 对我来说,我应该指定conf,所以我输入>> (sudo) redis-server /etc/redis/redis.conf
  • 谢谢。愚蠢的是,他们在教程中从未提到如何启动 redis 服务器!
  • redis-server --daemonize yes 在后台运行
  • @morteza-ziyae 如何在后台停止 redis 服务器?
【解决方案2】:

我用下一个方法解决这个问题:

sudo apt-get install redis-server

然后运行命令确认一切正常:

sudo service redis-server status

输出将是:redis-server is running - 这意味着问题已解决。

【讨论】:

  • 该错误已修复,但现在显示新错误,即“错误:ERR 'set' 命令的参数数量错误”
  • 谢谢!这解决了这个问题,只是在安装后重新运行命令redis-server 或在需要时添加 sudo 前缀后在 Linux/WSL 环境上做一个小说明。如果一切顺利,您将看到 redis-server cli 消息。也可以按照@author 的建议通过sudo service redis-server status 进行验证。
【解决方案3】:

首先在你的系统上安装redis -

brew install redis

然后启动redis服务器——

redis-server

【讨论】:

  • brew services start redis 更好
【解决方案4】:

我在 Windows 上,必须从 here 安装 Redis,然后运行 ​​redis-server.exe

this SO question的顶部。

【讨论】:

    【解决方案5】:

    简单的解决方案:

    只在下方点赞一次,然后再次重启服务器

    redis-server
    

    【讨论】:

      【解决方案6】:

      对于那些将 docker 与 docker-compose 和 Typescript 一起使用的人,我的解决方案是

      import { RedisClient } from 'redis';
      
       const pubClient = new RedisClient({ url: 'redis://redis:6379' });
      

      import { createClient } from 'redis';
      
      const pubClient = createClient({ url: 'redis://redis:6379' });
      

      docker-compose.yml

      version: '3.9'
      
      services:
        main:
          build:
            context: .
            target: development
          ports:
            - ${PORT}:${PORT}
          volumes:
            - ./src:/usr/src/app/src
            - /app/node_modules
          env_file:
            - .env
          command: npm run start:dev
          depends_on:
            - mongo
            - redis
        mongo:
          image: mongo:5.0.2-focal
          volumes:
            - mongo-data:/data/db
        mongo-express:
          image: mongo-express:0.54.0
          ports:
            - 8081:8081
          depends_on:
            - mongo
        redis:
          image: redis:6.2.5-alpine
      
      volumes:
        mongo-data:
      

      【讨论】:

      • 谢谢它解决了我的问题,不知道为什么它没有将端口和主机作为输入
      【解决方案7】:

      Windows用户可以使用chocolatey安装Redis

      choco install redis-64
      

      然后从

      运行服务器
      C:\ProgramData\chocolatey\lib\redis-64\redis-server.exe
      

      【讨论】:

        【解决方案8】:

        我也有同样的问题,首先我尝试通过sudo service restart重启redis-server,但问题依旧。然后我通过sudo apt-get purge redis-server 删除了redis-server 并通过sudo apt-get install redis-server 再次安装它,然后redis 再次工作。也值得看看位于这里的redis日志/var/log/redis/redis-server.log

        【讨论】:

          【解决方案9】:

          使用 Windows 10? 去这里:https://docs.microsoft.com/en-us/windows/wsl/wsl2-install

          然后运行...

              $ wget https://github.com/antirez/redis/archive/5.0.5.tar.gz <- change this to whatever Redis version you want (https://github.com/antirez/redis/releases)
              $ tar xzf redis-5.0.5.tar.gz
              $ cd redis-5.0.5
              $ make
          

          【讨论】:

            【解决方案10】:

            我用的是 ubuntu 12.04 我通过安装 redis-server 解决了这个问题

            redis-server installation for ubuntu 12.04

            一些配置将新的root权限 还列出了其他操作系统的手册

            谢谢

            【讨论】:

              【解决方案11】:

              对于 windows 平台,您必须检查 redis-server 是否在给定的 ip:port 上运行。你可以在安装目录/conf/redis.conf找到redis配置。默认情况下客户端接受127.0.0.1:6379

              【讨论】:

                【解决方案12】:

                我在 MBP 上,并安装 redis 详细信息我的问题已解决。修复 下载、解压和编译 Redis:

                $ wget http://download.redis.io/releases/redis-3.0.2.tar.gz
                
                $ tar xzf redis-3.0.2.tar.gz
                
                $ cd redis-3.0.2
                
                $ make
                

                现在编译的二进制文件在 src 目录中可用。

                运行 Redis:

                $ src/redis-server 
                

                【讨论】:

                  【解决方案13】:

                  我想你可能是通过源代码安装了 redis。如果你需要找到 redis-source-code-path/utils 并运行sudo install_server.sh 命令。 之后,确保 redis-server 已作为您系统的服务运行 sudo service redis-server status

                  PS:基于 Debian/Ubuntu

                  【讨论】:

                    【解决方案14】:

                    在 ubuntu 的情况下,错误是由于未设置 redis-server。 重新安装redis-server,然后检查状态。

                    如果没有错误,则会显示这样的消息:-

                    ● redis-server.service - 高级键值存储 已加载:已加载(/lib/systemd/system/redis-server.service;已启用;供应商预设:已启用) 活跃:自 2018 年 1 月 17 日星期三 IST 20:07:27 以来活跃(运行); 16 秒前 文档:http://redis.io/documentation, 人:redis服务器(1) 主PID:4327(redis-server) CGroup:/system.slice/redis-server.service └─4327 /usr/bin/redis-server 127.0.0.1:6379

                    【讨论】:

                      【解决方案15】:

                      你必须先安装redis服务器;

                      你可以按照以下步骤在mac上安装redis server -

                        $ curl -O http://download.redis.io/redis-stable.tar.gz
                        $ tar xzvf redis-stable.tar.gz
                        $ cd redis-stable
                        $ make
                        $ make test
                        $ sudo make install
                        $ redis-server
                      

                      祝你好运。

                      【讨论】:

                      • 注意:这需要一些时间来运行。如果您有依赖管理器(brew 或其他),这将节省您的时间。
                      【解决方案16】:

                      对我来说,我在 Ubuntu 18.x 上遇到了这个问题,但我的问题是我的 redis 服务器在 127.0.0.1 上运行,但我发现我需要在我的 IP 地址 xxx.xx.xx.xx 上运行它

                      我进入我的 Ubuntu 机器并执行了以下操作。

                      cd /etc/redis/

                      sudo vim redis.conf

                      然后我编辑了这部分。

                      ################################## NETWORK #####################################
                      
                      # By default, if no "bind" configuration directive is specified, Redis listens
                      # for connections from all the network interfaces available on the server.
                      # It is possible to listen to just one or multiple selected interfaces using
                      # the "bind" configuration directive, followed by one or more IP addresses.
                      #
                      # Examples:
                      #
                      # bind 192.168.1.100 10.0.0.1
                      # bind 127.0.0.1 ::1
                      #
                      # ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
                      # internet, binding to all the interfaces is dangerous and will expose the
                      # instance to everybody on the internet. So by default we uncomment the
                      # following bind directive, that will force Redis to listen only into
                      # the IPv4 loopback interface address (this means Redis will be able to
                      # accept connections only from clients running into the same computer it
                      # is running).le to listen to just one or multiple selected interfaces using
                      #
                      # IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
                      # JUST COMMENT THE FOLLOWING LINE.
                      # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                      # bind 127.0.0.1 ::1 10.0.0.1
                      bind 127.0.0.1 ::1 # <<-------- change this to what your iP address is something like (bind 192.168.2.2)
                      
                      

                      保存,然后重启 redis-server。

                      sudo service redis-server restart 或直接运行redis-server

                      【讨论】:

                        【解决方案17】:

                        您与 redis 的连接失败。尝试重新启动您的 redis 服务器,然后通过运行以下 3 个命令再次启动您的客户端:

                        sudo service redis-server restart
                        redis-server
                        redis-cli
                        

                        【讨论】:

                        • 请解释你的答案。它目前被视为低质量的帖子。谢谢!
                        • 我在 ubuntu 中遇到了这个错误......用这个命令解决......现在它工作正常......
                        【解决方案18】:

                        尝试将您的节点升级到最新版本。

                        sudo npm cache clean -f
                        sudo npm install -g n
                        sudo n stable
                        

                        0.4 版可能无法正常工作。

                        【讨论】:

                          猜你喜欢
                          • 2023-03-18
                          • 2017-05-16
                          • 2020-08-27
                          • 2017-07-06
                          • 1970-01-01
                          • 2019-01-03
                          • 2020-07-20
                          • 2020-12-25
                          • 2022-08-21
                          相关资源
                          最近更新 更多