UNPKG

6.63 kBTypeScriptView Raw
1/// <reference types="node" />
2import { ConnectionOptions } from 'tls';
3/**
4 * @see https://github.dev/luin/ioredis/blob/df04dd8d87a44d3b64b385c86581915248554508/lib/redis/RedisOptions.ts#L184
5 */
6export interface IORedisOptions {
7 Connector?: any;
8 retryStrategy?: (times: number) => number | void | null;
9 /**
10 * If a command does not return a reply within a set number of milliseconds,
11 * a "Command timed out" error will be thrown.
12 */
13 commandTimeout?: number;
14 /**
15 * Enable/disable keep-alive functionality.
16 * @link https://nodejs.org/api/net.html#socketsetkeepaliveenable-initialdelay
17 * @default 0
18 */
19 keepAlive?: number;
20 /**
21 * Enable/disable the use of Nagle's algorithm.
22 * @link https://nodejs.org/api/net.html#socketsetnodelaynodelay
23 * @default true
24 */
25 noDelay?: boolean;
26 /**
27 * Set the name of the connection to make it easier to identity the connection
28 * in client list.
29 * @link https://redis.io/commands/client-setname
30 */
31 connectionName?: string;
32 /**
33 * If set, client will send AUTH command with the value of this option as the first argument when connected.
34 * This is supported since Redis 6.
35 */
36 username?: string;
37 /**
38 * If set, client will send AUTH command with the value of this option when connected.
39 */
40 password?: string;
41 /**
42 * Database index to use.
43 *
44 * @default 0
45 */
46 db?: number;
47 /**
48 * When the client reconnects, channels subscribed in the previous connection will be
49 * resubscribed automatically if `autoResubscribe` is `true`.
50 * @default true
51 */
52 autoResubscribe?: boolean;
53 /**
54 * Whether or not to resend unfulfilled commands on reconnect.
55 * Unfulfilled commands are most likely to be blocking commands such as `brpop` or `blpop`.
56 * @default true
57 */
58 autoResendUnfulfilledCommands?: boolean;
59 /**
60 * Whether or not to reconnect on certain Redis errors.
61 * This options by default is `null`, which means it should never reconnect on Redis errors.
62 * You can pass a function that accepts an Redis error, and returns:
63 * - `true` or `1` to trigger a reconnection.
64 * - `false` or `0` to not reconnect.
65 * - `2` to reconnect and resend the failed command (who triggered the error) after reconnection.
66 * @example
67 * ```js
68 * const redis = new Redis({
69 * reconnectOnError(err) {
70 * const targetError = "READONLY";
71 * if (err.message.includes(targetError)) {
72 * // Only reconnect when the error contains "READONLY"
73 * return true; // or `return 1;`
74 * }
75 * },
76 * });
77 * ```
78 * @default null
79 */
80 reconnectOnError?: ((err: Error) => boolean | 1 | 2) | null;
81 /**
82 * @default false
83 */
84 readOnly?: boolean;
85 /**
86 * When enabled, numbers returned by Redis will be converted to JavaScript strings instead of numbers.
87 * This is necessary if you want to handle big numbers (above `Number.MAX_SAFE_INTEGER` === 2^53).
88 * @default false
89 */
90 stringNumbers?: boolean;
91 /**
92 * How long the client will wait before killing a socket due to inactivity during initial connection.
93 * @default 10000
94 */
95 connectTimeout?: number;
96 /**
97 * This option is used internally when you call `redis.monitor()` to tell Redis
98 * to enter the monitor mode when the connection is established.
99 *
100 * @default false
101 */
102 monitor?: boolean;
103 /**
104 * The commands that don't get a reply due to the connection to the server is lost are
105 * put into a queue and will be resent on reconnect (if allowed by the `retryStrategy` option).
106 * This option is used to configure how many reconnection attempts should be allowed before
107 * the queue is flushed with a `MaxRetriesPerRequestError` error.
108 * Set this options to `null` instead of a number to let commands wait forever
109 * until the connection is alive again.
110 *
111 * @default 20
112 */
113 maxRetriesPerRequest?: number | null;
114 /**
115 * @default 10000
116 */
117 maxLoadingRetryTime?: number;
118 /**
119 * @default false
120 */
121 enableAutoPipelining?: boolean;
122 /**
123 * @default []
124 */
125 autoPipeliningIgnoredCommands?: string[];
126 offlineQueue?: boolean;
127 commandQueue?: boolean;
128 /**
129 *
130 * By default, if the connection to Redis server has not been established, commands are added to a queue
131 * and are executed once the connection is "ready" (when `enableReadyCheck` is true, "ready" means
132 * the Redis server has loaded the database from disk, otherwise means the connection to the Redis
133 * server has been established). If this option is false, when execute the command when the connection
134 * isn't ready, an error will be returned.
135 *
136 * @default true
137 */
138 enableOfflineQueue?: boolean;
139 /**
140 * The client will sent an INFO command to check whether the server is still loading data from the disk (
141 * which happens when the server is just launched) when the connection is established, and only wait until
142 * the loading process is finished before emitting the `ready` event.
143 *
144 * @default true
145 */
146 enableReadyCheck?: boolean;
147 /**
148 * When a Redis instance is initialized, a connection to the server is immediately established. Set this to
149 * true will delay the connection to the server until the first command is sent or `redis.connect()` is called
150 * explicitly.
151 *
152 * @default false
153 */
154 lazyConnect?: boolean;
155 /**
156 * @default undefined
157 */
158 scripts?: Record<string, {
159 lua: string;
160 numberOfKeys?: number;
161 readOnly?: boolean;
162 }>;
163 keyPrefix?: string;
164 showFriendlyErrorStack?: boolean;
165 disconnectTimeout?: number;
166 tls?: ConnectionOptions;
167 /**
168 * Master group name of the Sentinel
169 */
170 name?: string;
171 /**
172 * @default "master"
173 */
174 role?: 'master' | 'slave';
175 sentinelUsername?: string;
176 sentinelPassword?: string;
177 sentinels?: Array<Partial<any>>;
178 sentinelRetryStrategy?: (retryAttempts: number) => number | void | null;
179 sentinelReconnectStrategy?: (retryAttempts: number) => number | void | null;
180 preferredSlaves?: any;
181 sentinelCommandTimeout?: number;
182 enableTLSForSentinelMode?: boolean;
183 sentinelTLS?: ConnectionOptions;
184 natMap?: any;
185 updateSentinels?: boolean;
186 /**
187 * @default 10
188 */
189 sentinelMaxConnections?: number;
190 failoverDetector?: boolean;
191}