"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.__tsfTypeAliases = exports.DEFAULT_REDIS_UNAVAILABLE_ALERT_AFTER_MS = void 0;
exports.monitorRedisAvailability = monitorRedisAvailability;
const availability_1 = require("../availability");
exports.DEFAULT_REDIS_UNAVAILABLE_ALERT_AFTER_MS = availability_1.DEFAULT_AVAILABILITY_ALERT_AFTER_MS;
function monitorRedisAvailability(client, logger, options = {}) {
    const monitor = (0, availability_1.createAvailabilityMonitor)(logger, { ...options, name: options.name ?? 'Redis' });
    const onError = (error) => monitor.unavailable(error);
    const onReconnecting = () => monitor.unavailable();
    const onReady = () => monitor.available();
    client.on('error', onError);
    client.on('reconnecting', onReconnecting);
    client.on('ready', onReady);
    return {
        unavailable: monitor.unavailable,
        available: monitor.available,
        stop() {
            client.removeListener('error', onError);
            client.removeListener('reconnecting', onReconnecting);
            client.removeListener('ready', onReady);
            monitor.stop();
        }
    };
}
exports.__tsfTypeAliases = JSON.parse("[1,{\"RedisAvailabilityClient\":{\"kind\":18,\"typeName\":\"RedisAvailabilityClient\",\"types\":[]},\"RedisAvailabilityMonitor\":{\"kind\":18,\"typeName\":\"AvailabilityMonitor\",\"types\":[],\"typeName\":\"RedisAvailabilityMonitor\"},\"RedisAvailabilityMonitorOptions\":{\"kind\":18,\"typeName\":\"AvailabilityMonitorOptions\",\"types\":[{\"kind\":20,\"name\":\"alertAfterMs\",\"type\":{\"kind\":12,\"types\":[{\"kind\":7},{\"kind\":4}]},\"optional\":true},{\"kind\":20,\"name\":\"name\",\"type\":{\"kind\":12,\"types\":[{\"kind\":6},{\"kind\":4}]},\"optional\":true},{\"kind\":20,\"name\":\"warningAfterMs\",\"type\":{\"kind\":12,\"types\":[{\"kind\":7},{\"kind\":4}]},\"optional\":true}],\"typeName\":\"RedisAvailabilityMonitorOptions\"}}]")[1];
//# sourceMappingURL=availability.js.map