UNPKG

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