1
0
mirror of synced 2025-12-23 11:54:18 -05:00

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:
James M. Greene
2021-04-02 10:28:24 -05:00
committed by GitHub
parent 78799b019e
commit 7cd58b06c7

View File

@@ -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})` : '') + ']'