Rajesh Khadka
Rajesh Khadka

Reputation: 61

RedisError: Redis connection needs to be open

I'm using redis-om with nodejs and I'm facing error !!

RedisError: Redis connection needs to be open

When I try to divide the app logic into controllers, routersit gets crashed , But it works completely fine if I make all the api's and endpoint in the main file (server.js) !!

The controller file's code :

This is controller file !!

Connection file to redis : Connection file

The actual error !! Actual error

Upvotes: 0

Views: 562

Answers (1)

Nelson Bwogora
Nelson Bwogora

Reputation: 2369

Your controller code has no opening of the redis client , you are only create a new client and then call it before opening it ,error is coming from the line

redisClient.fetchRepository(codeSchema)

here you are trying to use redis client before opening it

Have the file connecting redis client right after line 4

  1. the process is create new redis client - done on line 4
  2. call open on the client (not done on the controller thus error)
  3. Use the client to fetch etc

Below will work

const redisClient = new Client()
await redisClient.open('redis://localhost:6379')

then call

redisClient.fetchRepository(codeSchema)

Upvotes: 1

Related Questions