Redis: prevent offline queuing and retries for commands (#18561)
* Add an error handler to ensure the Redis server connection is forcibly closed * Disable the Redis offline queue and retries
This commit is contained in:
@@ -42,10 +42,30 @@ module.exports = function createClient (options = {}) {
|
||||
}
|
||||
},
|
||||
|
||||
// Any running command that is unfulfilled when a connection is lost should
|
||||
// NOT be retried after the connection has been reestablished.
|
||||
retry_unfulfilled_commands: false,
|
||||
|
||||
// If we failed to send a new command during a disconnection, do NOT
|
||||
// enqueue it to send later after the connection has been [re-]established.
|
||||
// This is also critical to preventing a backend pile-up!
|
||||
enable_offline_queue: false,
|
||||
|
||||
// Expand whatever other options and overrides were provided
|
||||
...options
|
||||
})
|
||||
|
||||
// Handle connection errors to prevent killing the Node.js process
|
||||
client.on('error', (connectError) => {
|
||||
try {
|
||||
// Forcibly close the connection to the Redis server.
|
||||
// Allow all still running commands to silently fail immediately.
|
||||
client.end(false)
|
||||
} catch (disconnectError) {
|
||||
// Swallow any failure
|
||||
}
|
||||
})
|
||||
|
||||
// If a `name` was provided, use it in the prefix for logging event messages
|
||||
const logPrefix = '[redis' + (name ? ` (${name})` : '') + ']'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user