(private readonly client: CacheClient)
| 11 | private scriptShas: Map<string, string> = new Map() |
| 12 | |
| 13 | public constructor(private readonly client: CacheClient) { |
| 14 | this.connection = client.isOpen ? Promise.resolve() : client.connect() |
| 15 | |
| 16 | this.connection.catch((error) => this.onClientError(error)) |
| 17 | |
| 18 | this.client |
| 19 | .on('connect', () => logger('connecting')) |
| 20 | .on('ready', () => logger('connected')) |
| 21 | .on('error', (error) => this.onClientError(error)) |
| 22 | .on('reconnecting', () => { |
| 23 | logger('reconnecting') |
| 24 | this.connection = new Promise((resolve, reject) => { |
| 25 | const cleanup = () => { |
| 26 | this.client.removeListener('ready', onReady) |
| 27 | this.client.removeListener('error', onError) |
| 28 | } |
| 29 | |
| 30 | const onError = (error: Error) => { |
| 31 | cleanup() |
| 32 | reject(error) |
| 33 | } |
| 34 | |
| 35 | const onReady = () => { |
| 36 | cleanup() |
| 37 | resolve() |
| 38 | } |
| 39 | |
| 40 | this.client.once('ready', onReady) |
| 41 | |
| 42 | this.client.once('error', onError) |
| 43 | }) |
| 44 | }) |
| 45 | } |
| 46 | |
| 47 | private onClientError(error: Error) { |
| 48 | logger.error('Unable to connect to Redis.', error) |
nothing calls this directly
no test coverage detected