|
1 | 1 | /// <reference types="node" /> |
2 | | -import IoRedis from 'ioredis'; |
3 | | -import EventEmitter from 'events'; |
| 2 | +import { Redis as _Redis, Cluster } from "ioredis"; |
| 3 | +import EventEmitter from "events"; |
| 4 | +interface RedisConfig { |
| 5 | + /** provide host ip/url, default - localhost */ |
| 6 | + host?: string; |
| 7 | + /** provide the port number, default - 6379 */ |
| 8 | + port?: number; |
| 9 | + /** provide the db number, default - 0 */ |
| 10 | + db?: number; |
| 11 | + /** enable auto pipelining, default - false */ |
| 12 | + autoPipelining?: boolean; |
| 13 | + /** provide auth if needed */ |
| 14 | + auth?: { |
| 15 | + use: boolean; |
| 16 | + password: string; |
| 17 | + }; |
| 18 | + /** provide command timeout (not applicable for cluster), default - false */ |
| 19 | + commandTimeout?: number; |
| 20 | + /** cluster config */ |
| 21 | + cluster?: { |
| 22 | + use: boolean; |
| 23 | + hosts: { |
| 24 | + host: string; |
| 25 | + port: number; |
| 26 | + }[]; |
| 27 | + autoPipelining?: boolean; |
| 28 | + }; |
| 29 | + /** sentinel config */ |
| 30 | + sentinel?: { |
| 31 | + use: boolean; |
| 32 | + hosts: { |
| 33 | + host: string; |
| 34 | + port: number; |
| 35 | + }[]; |
| 36 | + name: string; |
| 37 | + autoPipelining?: boolean; |
| 38 | + }; |
| 39 | +} |
4 | 40 | /** |
5 | 41 | * @class Redis |
6 | 42 | */ |
7 | 43 | declare class Redis { |
8 | 44 | name: string; |
9 | 45 | emitter: EventEmitter; |
10 | | - config: Record<string, any>; |
11 | | - client: IoRedis.Cluster | IoRedis.Redis; |
| 46 | + config: RedisConfig; |
| 47 | + client: Cluster | _Redis; |
12 | 48 | /** |
13 | 49 | * @param {string} name - unique name to this service |
14 | 50 | * @param {EventEmitter} emitter |
15 | | - * @param {Object} config - configuration object of service |
| 51 | + * @param {RedisConfig} config - configuration object of service |
16 | 52 | */ |
17 | | - constructor(name: string, emitter: EventEmitter, config: Record<string, any>); |
| 53 | + constructor(name: string, emitter: EventEmitter, config: RedisConfig); |
18 | 54 | log(message: string, data: unknown): void; |
19 | 55 | success(message: string, data: unknown): void; |
20 | 56 | error(err: Error, data: unknown): void; |
|
0 commit comments