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

189
Vistas
Using a Redis Singleton for NextJS API Routes

In my NextJS app, I have multiple API routes:

  • /api/user/[id]
  • /api/questions
  • /api/posts

Each of these endpoints uses a Redis connection to get or put data within a Redis server.

I've noticed that I get errors in my console, because I am making too many connections to the Redis server. So I had an idea of creating a Singleton class and connecting to the Redis server once within the singleton. getInstance() returns the connection.

But I've noticed that my singleton is created once per API route. Does NextJS do something to cause this to happen?

How can I create 1 instance of a Redis connection in a NextJS app, just for the API routes held inside of pages/api? I'm using ioredis library.

about 4 years ago · Juan Pablo Isaza
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