Redisgraph.js graph.close()

Hi, I am using the Redisgraph.js client library and the documentation is not very clear to me.

In the documentation, it looks like the graph should be initialized and closed on each request, but I suspect I misundertood that.

So I created a document to initialize the graph.
I export the initialization function to app.js and the graph object to the controllers, where I do the queries.

I am closing it on process.on(“SIGINT”) on app.js.
Is that right?

Best Regards

The sample on GitHub is showing a simple open, do stuff, close pattern. It’s just showing off all the capabilities in a simple but functional snippet of code. It is not an example of how you should build things as you don’t want to close your connections after each request. You’ll want to hang on to them and reuse them as they cost resources to create.

Your approach of closing the connection when the program is done—on an exit event handler or a SIGINT event handler—is fine. Much better than what I’ve done in the past, which is just let them hang! :wink:

However, I would suggest using Node Redis to open and close the connection and then handing the Node Redis connection to redisgraph.js. This will allow you to use the connection for more mundane Redis operations as well. Plus, Node Redis has more options on opening that connection than redisgraph.js has. I have a simple bit of code from a past project that you/re welcome to reference that shows the basics.

1 Like

Thank you very much!! I was not sure if I was closing it correctly…
I will take a look at your node redis implementation.
Best Regards!