Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

307
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda