UNPKG

symspell-ex

Version:

Spelling correction & Fuzzy search based on symmetric delete spelling correction algorithm

74 lines (73 loc) 2 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Redis = exports.RedisConfig = void 0; const ioredis_1 = __importDefault(require("ioredis")); const RETRY_COUNT = 15; const RETRY_DELAY = 100; const RETRY_DELAY_MIN = 2000; class RedisConfig { constructor(host, port, password, db = 0) { this.port = 6379; this.db = 0; this.host = host; this.port = port; this.password = password; this.db = db; } } exports.RedisConfig = RedisConfig; class Redis { /** * * @param config * { * host: {type: 'string'}, * port: {type: 'number'}, * password: {type: 'string'}, * db: {type: 'number'}, * onConnected: {type: 'function'} * } */ constructor(config) { this._isConnected = false; // @ts-ignore const { host, port, password, db } = config; this._config = { host, port, password, db, enableReadyCheck: true, lazyConnect: true, retryStrategy: (times) => { const delay = Math.min(times * RETRY_DELAY, RETRY_DELAY_MIN); if (times <= RETRY_COUNT) { return delay; } return false; } }; const self = this; this._db = new ioredis_1.default(this._config); this._db.on('ready', async () => { // console.log('Connected to redis'); self._isConnected = true; }); } async connect() { return this._db.connect(); } async isConnected() { return this._isConnected; } async disconnect() { return this._db.disconnect(); } get instance() { return this._db; } } exports.Redis = Redis;