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 ?