integrating redis into serverless

588 Views Asked by At

I am looking at integrating a caching service with serverless.

I have decided to go with redis. However through reading through the npm redis, it seems that you are required to call client.quit() after completing the request.

The way serverless seems to work is that the instance is spawned, and then deleted when not in use. So I was wondering if there was a way to quit the redis connection when the serverless instance is being deleted.

Or whether I just have to actually just start a connection on every request, and quit the connection before each request finishes.

I was hoping I could do it on the app state, instead of request state, that way I wont have to spawn so many connections.

1

There are 1 best solutions below

7
On

No. A connection could be reused. It does not need to start a new connection on every request.

If you use the redis.creatClient() to create a connection, you could use this connection always in your app. And it has reconnect mechanism if the connection is broken. So in your app development, you do not need to care the connection problem, just get a global connection and always use it.