Skip to content

Instantly share code, notes, and snippets.

@victusfate
Created October 20, 2017 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save victusfate/0daba3e809912b9ebcf2fcf248a263f5 to your computer and use it in GitHub Desktop.
Save victusfate/0daba3e809912b9ebcf2fcf248a263f5 to your computer and use it in GitHub Desktop.
clean up your redis client connections! make a call to this whenever you create a new client
const cleanupClientOnProcessEnd = (options) => {
const sAction = 'cache.cleanupClientOnProcessEnd';
const name = options.name;
let client = options.client;
const killDelayTime = 500;
const killClient = (sType) => {
// console.info({action: `${name}.${sAction}.${sType}.client.quit` });
client.quit();
setTimeout( () => {
client.end(true);
// console.info({action: `${name}.${sAction}.${sType}.client.end` });
if (sType === 'SIGINT' || sType == 'SIGTERM') {
process.exit(0);
}
},killDelayTime);
}
process.on( 'SIGINT', () => {
killClient('SIGINT');
});
process.on( 'SIGTERM', () => {
killClient('SIGTERM');
});
process.on('exit', (code) => {
killClient('exit code' + code);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment