Skip to main content

Function: attachRedisErrorHandler()

attachRedisErrorHandler<T>(client, logger, name): T

Defined in: service-core/src/database/ConnectionManager.ts:33

Attaches error, reconnecting and ready listeners that log a redis client's connection problems.

A node-redis client emits error whenever its socket fails (e.g. the server restarts or the network drops). An EventEmitter with no error listener throws on that event, which crashes the whole process. With a listener, the client's own reconnect strategy (exponential backoff, retried indefinitely by default) takes over and pending subscriptions are restored once it reconnects.

To avoid flooding the log while a server is unreachable, the first error of an outage is logged as an error and the following ones as debug messages, until the client is ready again. Every client this library creates, and every duplicate() of one, must be passed through this function. Calling it again on the same client does nothing.

Type Parameters​

T​

T

Parameters​

client​

T

The redis client to attach the listeners to. Clients without an on() method are ignored.

logger​

any

The logger to report errors to.

name​

string

A name for the client, used in log messages.

Returns​

T

The given client.