Created
October 20, 2017 16:45
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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