0
votes

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 oncomplete] (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 command,
operable program or batch file.

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

Any suggestions ?

3

3 Answers

2
votes

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

https://github.com/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.

0
votes

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.

0
votes

'redis-server' is not recognized as an internal or external command, 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.