#StackBounty: #javascript #node.js #redis #node-redis Node.js: Closing all Redis clients on shutdown

Bounty: 50

Today, I integrated Redis into my node.js application and am using it as a session store. Basically, upon successful authentication, I store the corresponding user object in Redis.

When I receive http requests after authentication, I attempt to retrieve the user object from Redis using a hash. If the retrieval was successful, that means the user is logged in and the request can be fulfilled.

The act of storing the user object in Redis and the retrieval happen in two different files, so I have one Redis client in each file.

Question 1:
Is it ok having two Redis clients, one in each file? Or should I instantiate only one client and use it across all areas of the application?

Question 2:
Does the node-redis library provide a method to show a list of connected clients? If it does, I will be able to iterate through the list, and call client.quit() for each of them when the server is shutting down.

By the way, this is how I’m implementing the “graceful shutdown” of the server:

//Gracefully shutdown and perform clean-up when kill signal is received
process.on('SIGINT', cleanup);
process.on('SIGTERM', cleanup);

function cleanup() {
    server.stop(function() {
        //todo: quit all connected redis clients

        console.log('Server stopped.');

        //exit the process

Get this bounty!!!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.