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

190
Views
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
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!