Home > Back-end >  Node Redis does not work on my windows computer even though the server is up and running
Node Redis does not work on my windows computer even though the server is up and running

Time:11-29

const express = require("express");
const redis = require("redis");
const app = express();

const client = redis.createClient({
  url: "redis://[email protected]",
});

client.on("connect", function () {
  console.log("redis connected");
  console.log(`connected ${redisClient.connected}`);
});

client.on("error", (err) => {
  console.log(err);
});

app.listen(process.env.PORT || 3000, () => {
  console.log("Node server started");
});

The above code does not show any connection to redis server even though I have checked the EC2 redis instance by connecting using Redsmin. hosting details in Redsmin

This is a very simple thing to do but the error that I get cannot be googled.

Node server started C:\Users\Sithira_105661\Desktop\Projects\Learning\Redis\node_modules@node-redis\client\dist\lib\client\index.js:387 return Promise.reject(new errors_1.ClientClosedError()); ^

ClientClosedError: The client is closed at Commander._RedisClient_sendCommand (C:\Users\Sithira_105661\Desktop\Projects\Learning\Redis\node_modules@node-redis\client\dist\lib\client\index.js:387:31) at Commander.commandsExecutor (C:\Users\Sithira_105661\Desktop\Projects\Learning\Redis\node_modules@node-redis\client\dist\lib\client\index.js:160:154) at Commander.BaseClass. [as set] (C:\Users\Sithira_105661\Desktop\Projects\Learning\Redis\node_modules@node-redis\client\dist\lib\commander.js:8:29) at Object. (C:\Users\Sithira_105661\Desktop\Projects\Learning\Redis\redis.js:19:8) at Module._compile (node:internal/modules/cjs/loader:1101:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10) at Module.load (node:internal/modules/cjs/loader:981:32) at Function.Module._load (node:internal/modules/cjs/loader:822:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) at node:internal/main/run_main_module:17:47

Help me understand the issue. Thanks in advance.

CodePudding user response:

Please check your ec2 redis connection

    const client = redis.createClient({
       url: "redis://username:password@ec2_endpoint:port",
     });

Connection string format: redis[s]://[[username][:password]@][host][:port]

CodePudding user response:

finally found the solution. I used node-redis 3.0.0 rather than 4 and the code works fine. I do not know why it does not work in latest node-redis . If any of you guys are getting this issue use node-redis 3

  • Related