UNPKG

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