【问题标题】:Redis keeps failing on Windows 10 with Node.JS : Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379Redis 在带有 Node.JS 的 Windows 10 上一直失败:错误:Redis 连接到 127.0.0.1:6379 失败 - 连接 ECONNREFUSED 127.0.0.1:6379
【发布时间】:2020-07-20 12:35:41
【问题描述】:

考虑代码:

const mongoose = require("mongoose");
const redis = require("redis");
const util = require("util");

const redisUrl = "redis://127.0.0.1:6379";
const client = redis.createClient(redisUrl);
client.hget = util.promisify(client.hget);
const exec = mongoose.Query.prototype.exec;

mongoose.Query.prototype.cache = function(options = {}) {
  this.useCache = true;
  this.hashKey = JSON.stringify(options.key || "");
  return this; // now it's chainable
};

   ... // More code ...

它产生:

events.js:173 投掷者; // 未处理的“错误”事件 [0] ^ [0] [0] 错误:Redis 连接到 127.0.0.1:6379 失败 - 连接 ECONNREFUSED 127.0.0.1:6379 [0] 在 TCPConnectWrap.afterConnect [as oncomplete] (net.js:1054:14) [0] 在 [0] 处发出“错误”事件 RedisClient.on_error (C:\Development-X220\NODEJS\Redis\node_modules\redis\index.js:341:14) [0] 在套接字。 (C:\Development-X220\NODEJS\Redis\node_modules\redis\index.js:222:14) [0] 在 Socket.emit (events.js:196:13) [0] 在 emitErrorNT (internal/streams/destroy.js:91:8) [0] 在 emitErrorAndCloseNT (内部/流/destroy.js:59:3) [0] 在 processTicksAndRejections (internal/process/task_queues.js:84:9) [0] [nodemon] 应用程序崩溃 - 启动前等待文件更改...

还有:

Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379

知道如何解决吗?

我尝试从 Windows-10 的 CMD 运行 redis-server 并得到:

'redis-server' is not recognized as an internal or external command,
operable program or batch file.

还遵循了人们提供的建议 here 但没有任何效果。

有什么建议吗?

【问题讨论】:

    标签: javascript node.js redis windows-10


    【解决方案1】:

    您需要在使用之前安装软件,这就是近 50 年来的情况。考虑this guide 在 Windows 上安装 Redis。

    【讨论】:

    • 已经完成了,从这里在我的机器上安装了 Redis:github.com/rgl/redis/downloads
    • 'redis-server' is not recognized... 表示出现问题,请仔细检查您的安装。
    【解决方案2】:

    'redis-server' 不是内部或外部命令、可运行程序或批处理文件。

    这意味着您的 redis 服务器尚未运行,因此超时错误是意料之中的。

    我认为 Windows 的 redis 不是官方的,所以最好在 docker 或 linux 主机中运行 redis。

    【讨论】:

      【解决方案3】:

      好的,我已经通过这个链接修复了它:

      https://github.com/rgl/redis/downloads

      我正在为可能遇到相同问题的任何人发布阶段:

      选择最上面的 EXE 文件并安装它。

      在 Windows 10 之后,点击:FN + R

      类型:services.msc

      在列表中寻找“Redis Server”,右键选择 “开始”。

      就是这样,你已经启动并运行了。

      【讨论】:

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