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

313
Views
How to reuse Redis connection using nodeJs childProcess

How could I reuse the redis connection in processes created using Childprocess.fork() in nodeJs ?

For example, I would have a redis-config.js file where I create an instance of RedisClient and connect to the redis server. So after that I would have another file, test.js for example, and inside that file test, js I would access the instance of redis via import and then I could for example insert a key in redis. But this without creating another connection to the redis server.

For example

redis-conf.js

    const Redis = require('redis');

const redisClient = Redis.createClient({name:'test-conecction'});

module.exports = {redisClient:Object.freeze(redisClient)}

main.js

    const cp = require('node:child_process');
const {redisClient} = require('./redis');

redisClient.connect().then(()=>{  <<=== this is want i want, this does not work, i want to connect only once.
const c1 = cp.fork('./child.js');
const c2 = cp.fork('./child.js');
})

child.js

    const {redisClient} = require('./redis');

redisClient.info().then((data)=>{  <<== when i try this, nodeJs tells that the client is disconnected
    console.log(data);
})
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

IN resume. Its not possible. Because when nodeJs create a childPorcess evething is re-created and all resources are re-alocated.

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!