1 | /// <reference types="node" />
|
2 | import { SrvRecord } from "dns";
|
3 | import { RedisOptions } from "../redis/RedisOptions";
|
4 | import { CommanderOptions } from "../utils/Commander";
|
5 | import { NodeRole } from "./util";
|
6 | export declare type DNSResolveSrvFunction = (hostname: string, callback: (err: NodeJS.ErrnoException | null | undefined, records?: SrvRecord[]) => void) => void;
|
7 | export declare type DNSLookupFunction = (hostname: string, callback: (err: NodeJS.ErrnoException | null | undefined, address: string, family?: number) => void) => void;
|
8 | export interface NatMap {
|
9 | [key: string]: {
|
10 | host: string;
|
11 | port: number;
|
12 | };
|
13 | }
|
14 | /**
|
15 | * Options for Cluster constructor
|
16 | */
|
17 | export interface ClusterOptions extends CommanderOptions {
|
18 | /**
|
19 | * See "Quick Start" section.
|
20 | *
|
21 | * @default (times) => Math.min(100 + times * 2, 2000)
|
22 | */
|
23 | clusterRetryStrategy?: (times: number, reason?: Error) => number | void | null;
|
24 | /**
|
25 | * See Redis class.
|
26 | *
|
27 | * @default true
|
28 | */
|
29 | enableOfflineQueue?: boolean;
|
30 | /**
|
31 | * When enabled, ioredis only emits "ready" event when `CLUSTER INFO`
|
32 | * command reporting the cluster is ready for handling commands.
|
33 | *
|
34 | * @default true
|
35 | */
|
36 | enableReadyCheck?: boolean;
|
37 | /**
|
38 | * Scale reads to the node with the specified role.
|
39 | *
|
40 | * @default "master"
|
41 | */
|
42 | scaleReads?: NodeRole | Function;
|
43 | /**
|
44 | * When a MOVED or ASK error is received, client will redirect the
|
45 | * command to another node.
|
46 | * This option limits the max redirections allowed to send a command.
|
47 | *
|
48 | * @default 16
|
49 | */
|
50 | maxRedirections?: number;
|
51 | /**
|
52 | * When an error is received when sending a command (e.g.
|
53 | * "Connection is closed." when the target Redis node is down), client will retry
|
54 | * if `retryDelayOnFailover` is valid delay time (in ms).
|
55 | *
|
56 | * @default 100
|
57 | */
|
58 | retryDelayOnFailover?: number;
|
59 | /**
|
60 | * When a CLUSTERDOWN error is received, client will retry
|
61 | * if `retryDelayOnClusterDown` is valid delay time (in ms).
|
62 | *
|
63 | * @default 100
|
64 | */
|
65 | retryDelayOnClusterDown?: number;
|
66 | /**
|
67 | * When a TRYAGAIN error is received, client will retry
|
68 | * if `retryDelayOnTryAgain` is valid delay time (in ms).
|
69 | *
|
70 | * @default 100
|
71 | */
|
72 | retryDelayOnTryAgain?: number;
|
73 | /**
|
74 | * By default, this value is 0, which means when a `MOVED` error is received,
|
75 | * the client will resend the command instantly to the node returned together with
|
76 | * the `MOVED` error. However, sometimes it takes time for a cluster to become
|
77 | * state stabilized after a failover, so adding a delay before resending can
|
78 | * prevent a ping pong effect.
|
79 | *
|
80 | * @default 0
|
81 | */
|
82 | retryDelayOnMoved?: number;
|
83 | /**
|
84 | * The milliseconds before a timeout occurs while refreshing
|
85 | * slots from the cluster.
|
86 | *
|
87 | * @default 1000
|
88 | */
|
89 | slotsRefreshTimeout?: number;
|
90 | /**
|
91 | * The milliseconds between every automatic slots refresh.
|
92 | *
|
93 | * @default 5000
|
94 | */
|
95 | slotsRefreshInterval?: number;
|
96 | /**
|
97 | * Passed to the constructor of `Redis`
|
98 | *
|
99 | * @default null
|
100 | */
|
101 | redisOptions?: Omit<RedisOptions, "port" | "host" | "path" | "sentinels" | "retryStrategy" | "enableOfflineQueue" | "readOnly">;
|
102 | /**
|
103 | * By default, When a new Cluster instance is created,
|
104 | * it will connect to the Redis cluster automatically.
|
105 | * If you want to keep the instance disconnected until the first command is called,
|
106 | * set this option to `true`.
|
107 | *
|
108 | * @default false
|
109 | */
|
110 | lazyConnect?: boolean;
|
111 | /**
|
112 | * Discover nodes using SRV records
|
113 | *
|
114 | * @default false
|
115 | */
|
116 | useSRVRecords?: boolean;
|
117 | /**
|
118 | * SRV records will be resolved via this function.
|
119 | *
|
120 | * You may provide a custom `resolveSrv` function when you want to customize
|
121 | * the cache behavior of the default function.
|
122 | *
|
123 | * @default require('dns').resolveSrv
|
124 | */
|
125 | resolveSrv?: DNSResolveSrvFunction;
|
126 | /**
|
127 | * Hostnames will be resolved to IP addresses via this function.
|
128 | * This is needed when the addresses of startup nodes are hostnames instead
|
129 | * of IPs.
|
130 | *
|
131 | * You may provide a custom `lookup` function when you want to customize
|
132 | * the cache behavior of the default function.
|
133 | *
|
134 | * @default require('dns').lookup
|
135 | */
|
136 | dnsLookup?: DNSLookupFunction;
|
137 | natMap?: NatMap;
|
138 | /**
|
139 | * See Redis class.
|
140 | *
|
141 | * @default false
|
142 | */
|
143 | enableAutoPipelining?: boolean;
|
144 | /**
|
145 | * See Redis class.
|
146 | *
|
147 | * @default []
|
148 | */
|
149 | autoPipeliningIgnoredCommands?: string[];
|
150 | /**
|
151 | * Custom LUA commands
|
152 | */
|
153 | scripts?: Record<string, {
|
154 | lua: string;
|
155 | numberOfKeys?: number;
|
156 | readOnly?: boolean;
|
157 | }>;
|
158 | }
|
159 | export declare const DEFAULT_CLUSTER_OPTIONS: ClusterOptions;
|