【发布时间】: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