最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Redis keeps failing on Windows 10 with Node.JS : Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNRE

programmeradmin1浏览0评论

Consider the code :

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 ...

It produces :

events.js:173 throw er; // Unhandled 'error' event [0] ^ [0] [0] Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379 [0] at TCPConnectWrap.afterConnect [as onplete] (net.js:1054:14) [0] Emitted 'error' event at: [0] at RedisClient.on_error (C:\Development-X220\NODEJS\Redis\node_modules\redis\index.js:341:14) [0] at Socket. (C:\Development-X220\NODEJS\Redis\node_modules\redis\index.js:222:14) [0] at Socket.emit (events.js:196:13) [0] at emitErrorNT (internal/streams/destroy.js:91:8) [0] at emitErrorAndCloseNT (internal/streams/destroy.js:59:3) [0] at processTicksAndRejections (internal/process/task_queues.js:84:9) [0] [nodemon] app crashed - waiting for file changes before starting...

And also :

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

Any idea how to fix it ?

I've tried to run redis-server from CMD of Windows-10 and got :

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

Also followed on the suggestions people offered here but nothing worked.

Any suggestions ?

Consider the code :

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 ...

It produces :

events.js:173 throw er; // Unhandled 'error' event [0] ^ [0] [0] Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379 [0] at TCPConnectWrap.afterConnect [as onplete] (net.js:1054:14) [0] Emitted 'error' event at: [0] at RedisClient.on_error (C:\Development-X220\NODEJS\Redis\node_modules\redis\index.js:341:14) [0] at Socket. (C:\Development-X220\NODEJS\Redis\node_modules\redis\index.js:222:14) [0] at Socket.emit (events.js:196:13) [0] at emitErrorNT (internal/streams/destroy.js:91:8) [0] at emitErrorAndCloseNT (internal/streams/destroy.js:59:3) [0] at processTicksAndRejections (internal/process/task_queues.js:84:9) [0] [nodemon] app crashed - waiting for file changes before starting...

And also :

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

Any idea how to fix it ?

I've tried to run redis-server from CMD of Windows-10 and got :

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

Also followed on the suggestions people offered here but nothing worked.

Any suggestions ?

Share Improve this question asked Apr 8, 2020 at 6:57 JANJAN 21.9k66 gold badges190 silver badges336 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 4

OK , I've fixed it by going to this link :

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

I'm posting the stages for anyone who might encounter the same problem :

Picking the top EXE file and installing it.

After that in Windows 10 , hit : FN + R

Type : services.msc

Look for the "Redis Server" in the list , right click and choose "Start".

That's it , you're up and running.

You need to install software before using it, this is how it has been for recent 50 years. Consider this guide on installing Redis on Windows.

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

that means your redis server is not running yet so the timeout error is kind of expected.

redis for windows is not official i think so it's best you run redis in docker or a linux host.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论