Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

279
Views
Cannot connect to Redis using node js module

I have redis up and running on port 6379, connecting via telnet works fine.

I'm trying to connect to it on node.js, but i'm getting no response from the event listeners. If i make a call any function like client.set() I get: "ClientClosedError: The client is closed".

This is the code im running:

const redis = require('redis');
const client = redis.createClient(6379);

client.on('connect', () => {
    console.log('connected');
});
client.on('end', () => {
    console.log('disconnected');
});
client.on('reconnecting', () => {
    console.log('reconnecting');
});
client.on('error', (err) => {
    console.log('error', { err });
});

setTimeout(() => {console.log("goodbye") }, 20*1000 );

Nothing happens for 20 seconds, and then it closes

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Starting from v4 of node-redis library, you need to call client.connect() after initializing a client. See this migration guide.

const redis = require('redis');
const client = redis.createClient({ socket: { port: 6379 } });

client.connect();

client.on('connect', () => {
    console.log('connected');
});

You might also want to consider running the client connect method with await in an asynchronous function. So you don't have to worry about event listeners.

const redis = require('redis');

(async () => {
  try {
    const client = redis.createClient({ socket: { port: 6379 } });
    await client.connect();
    console.log('connected');
  } catch (err) {
    console.error(err)
  }
})()
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!