UNPKG

63.8 kBTypeScriptView Raw
1// Type definitions for ioredis 4.16
2// Project: https://github.com/luin/ioredis
3// Definitions by: York Yao <https://github.com/plantain-00>
4// Christopher Eck <https://github.com/chrisleck>
5// Yoga Aliarham <https://github.com/aliarham11>
6// Ebrahim <https://github.com/br8h>
7// Whemoon Jang <https://github.com/palindrom615>
8// Francis Gulotta <https://github.com/reconbot>
9// Dmitry Motovilov <https://github.com/funthing>
10// Oleg Repin <https://github.com/iamolegga>
11// Ting-Wai To <https://github.com/tingwai-to>
12// Alex Petty <https://github.com/pettyalex>
13// Simon Schick <https://github.com/SimonSchick>
14// Tianlin <https://github.com/tianlinle>
15// Demian Rodriguez <https://github.com/demian85>
16// Andrew Lavers <https://github.com/alavers>
17// Claudiu Ceia <https://github.com/ClaudiuCeia>
18// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
19// TypeScript Version: 2.8
20
21/* =================== USAGE ===================
22 import * as Redis from "ioredis";
23 const redis = new Redis();
24 =============================================== */
25
26/// <reference types="node" />
27
28import { ConnectionOptions } from 'tls';
29import { Readable } from 'stream';
30import { EventEmitter } from 'events';
31
32interface RedisStatic {
33 new (port?: number, host?: string, options?: IORedis.RedisOptions): IORedis.Redis;
34 new (host?: string, options?: IORedis.RedisOptions): IORedis.Redis;
35 new (options?: IORedis.RedisOptions): IORedis.Redis;
36 (port?: number, host?: string, options?: IORedis.RedisOptions): IORedis.Redis;
37 (host?: string, options?: IORedis.RedisOptions): IORedis.Redis;
38 (options?: IORedis.RedisOptions): IORedis.Redis;
39 Cluster: IORedis.ClusterStatic;
40 Command: typeof Command;
41}
42
43declare var IORedis: RedisStatic;
44export = IORedis;
45
46declare class Commander {
47 getBuiltinCommands(): string[];
48 createBuiltinCommand(commandName: string): {};
49 defineCommand(
50 name: string,
51 definition: {
52 numberOfKeys?: number;
53 lua?: string;
54 },
55 ): void;
56 sendCommand(): void;
57}
58
59interface CommandOptions {
60 replyEncoding?: string | null;
61 errorStack?: string;
62 keyPrefix?: string;
63}
64declare class Command {
65 isCustomCommand: boolean;
66 args: IORedis.ValueType[];
67 getSlot(): number | null;
68 getKeys(): Array<string | Buffer>;
69 constructor(
70 name: string,
71 args: IORedis.ValueType[],
72 opts?: CommandOptions,
73 callback?: (err: null, result: any) => void,
74 );
75 static setArgumentTransformer(name: string, fn: (args: IORedis.ValueType[]) => IORedis.ValueType[]): void;
76 static setReplyTransformer(name: string, fn: (result: any) => any): void;
77}
78
79// For backwards compatibility
80type _Command = typeof Command;
81
82declare namespace IORedis {
83 type BooleanResponse = 1 | 0;
84 type Callback<T> = (err: Error | null, res: T) => void;
85 type KeyType = string | Buffer;
86 type ValueType = string | Buffer | number | any[];
87
88 interface OverloadedCommand<T, U> {
89 (arg1: T, arg2: T, arg3: T, arg4: T, arg5: T, arg6: T, cb: Callback<U>): void;
90 (arg1: T, arg2: T, arg3: T, arg4: T, arg5: T, cb: Callback<U>): void;
91 (arg1: T, arg2: T, arg3: T, arg4: T, cb: Callback<U>): void;
92 (arg1: T, arg2: T, arg3: T, cb: Callback<U>): void;
93 (arg1: T, arg2: T, cb: Callback<U>): void;
94 (arg1: T | T[], cb: Callback<U>): void;
95 (cb: Callback<U>): void;
96 (...args: T[]): Promise<U>;
97 (arg1: T[]): Promise<U>;
98 }
99
100 interface OverloadedListCommand<T, U> {
101 (arg1: T, arg2: T, arg3: T, arg4: T, arg5: T, arg6: T, cb: Callback<U>): void;
102 (arg1: T, arg2: T, arg3: T, arg4: T, arg5: T, cb: Callback<U>): void;
103 (arg1: T, arg2: T, arg3: T, arg4: T, cb: Callback<U>): void;
104 (arg1: T, arg2: T, arg3: T, cb: Callback<U>): void;
105 (arg1: T, arg2: T, cb: Callback<U>): void;
106 (arg1: T | T[], cb: Callback<U>): void;
107 (...args: T[]): Promise<U>;
108 (arg1: T[]): Promise<U>;
109 }
110
111 interface OverloadedBlockingListCommand<T, U> {
112 (arg1: T, arg2: T, arg3: T, arg4: T, arg5: T, arg6: T, timeout: number, cb: Callback<U>): void;
113 (arg1: T, arg2: T, arg3: T, arg4: T, arg5: T, timeout: number, cb: Callback<U>): void;
114 (arg1: T, arg2: T, arg3: T, arg4: T, timeout: number, cb: Callback<U>): void;
115 (arg1: T, arg2: T, arg3: T, timeout: number, cb: Callback<U>): void;
116 (arg1: T, arg2: T, timeout: number, cb: Callback<U>): void;
117 (arg1: T, timeout: number, cb: Callback<U>): void;
118 (arg1: Array<T | number>, cb: Callback<U>): void;
119 (...args: Array<T | number>): Promise<U>;
120 (arg1: Array<T | number>): Promise<U>;
121 }
122
123 interface OverloadedSubCommand<T, U> {
124 (arg1: T, arg2: T, arg3: T, arg4: T, arg5: T, arg6: T, cb: Callback<U>): void;
125 (arg1: T, arg2: T, arg3: T, arg4: T, arg5: T, cb: Callback<U>): void;
126 (arg1: T, arg2: T, arg3: T, arg4: T, cb: Callback<U>): void;
127 (arg1: T, arg2: T, arg3: T, cb: Callback<U>): void;
128 (arg1: T, arg2: T | T[], cb: Callback<U>): void;
129 (arg1: T | T[], cb: Callback<U>): void;
130 (...args: T[]): Promise<U>;
131 (arg1: T[]): Promise<U>;
132 }
133
134 interface OverloadedKeyCommand<T, U> {
135 (key: KeyType, arg1: T, arg2: T, arg3: T, arg4: T, arg5: T, arg6: T, cb: Callback<U>): void;
136 (key: KeyType, arg1: T, arg2: T, arg3: T, arg4: T, arg5: T, cb: Callback<U>): void;
137 (key: KeyType, arg1: T, arg2: T, arg3: T, arg4: T, cb: Callback<U>): void;
138 (key: KeyType, arg1: T, arg2: T, arg3: T, cb: Callback<U>): void;
139 (key: KeyType, arg1: T, arg2: T, cb: Callback<U>): void;
140 (key: KeyType, arg1: T | T[], cb: Callback<U>): void;
141 (key: KeyType, ...args: T[]): Promise<U>;
142 (key: KeyType, arg1: T[]): Promise<U>;
143 }
144
145 interface OverloadedHashCommand<T, U> {
146 (arg1: T, arg2: T, arg3: T, arg4: T, arg5: T, arg6: T, cb: Callback<U>): void;
147 (arg1: T, arg2: T, arg3: T, arg4: T, cb: Callback<U>): void;
148 (arg1: T, arg2: T, cb: Callback<U>): void;
149 (data: T[] | { [key: string]: T } | Map<string, T>, cb: Callback<U>): void;
150 (data: T[] | { [key: string]: T } | Map<string, T>): Promise<U>;
151 (...args: T[]): Promise<U>;
152 }
153
154 interface OverloadedKeyedHashCommand<T, U> {
155 (key: KeyType, arg1: T, arg2: T, arg3: T, arg4: T, arg5: T, arg6: T, cb: Callback<U>): void;
156 (key: KeyType, arg1: T, arg2: T, arg3: T, arg4: T, cb: Callback<U>): void;
157 (key: KeyType, arg1: T, arg2: T, cb: Callback<U>): void;
158 (key: KeyType, data: T[] | { [key: string]: T } | Map<string, ValueType>, cb: Callback<U>): void;
159 (key: KeyType, data: T[] | { [key: string]: T } | Map<string, ValueType>): Promise<U>;
160 (key: KeyType, ...args: T[]): Promise<U>;
161 }
162
163 interface OverloadedEvalCommand<T, U> {
164 (script: string, numKeys: number, arg1: T, arg2: T, arg3: T, arg4: T, arg5: T, arg6: T, cb: Callback<U>): void;
165 (script: string, numKeys: number, arg1: T, arg2: T, arg3: T, arg4: T, arg5: T, cb: Callback<U>): void;
166 (script: string, numKeys: number, arg1: T, arg2: T, arg3: T, arg4: T, cb: Callback<U>): void;
167 (script: string, numKeys: number, arg1: T, arg2: T, arg3: T, cb: Callback<U>): void;
168 (script: string, numKeys: number, arg1: T, arg2: T, cb: Callback<U>): void;
169 (script: string, numKeys: number, arg1: T | T[], cb: Callback<U>): void;
170 (script: string, numKeys: number, ...args: T[]): Promise<U>;
171 (script: string, numKeys: number, arg1: T[]): Promise<U>;
172 // This overload exists specifically to retain compatibility to `redlock`
173 // All arguments are by default flattened, declaring all possible permuatations
174 // would be unreasonable (and probably impossible)
175 (args: ValueType[], callback?: Callback<any>): any;
176 }
177
178 interface OverloadedScanCommand<T, U> {
179 (key: string, cursor: number, arg1: T, arg2: T, arg3: T, arg4: T, arg5: T, arg6: T, cb: Callback<U>): void;
180 (key: string, cursor: number, arg1: T, arg2: T, arg3: T, arg4: T, arg5: T, cb: Callback<U>): void;
181 (key: string, cursor: number, arg1: T, arg2: T, arg3: T, arg4: T, cb: Callback<U>): void;
182 (key: string, cursor: number, arg1: T, arg2: T, arg3: T, cb: Callback<U>): void;
183 (key: string, cursor: number, arg1: T, arg2: T, cb: Callback<U>): void;
184 (key: string, cursor: number, arg1: T | T[], cb: Callback<U>): void;
185 (key: string, cursor: number, cb: Callback<U>): void;
186 (key: string, cursor: number, ...args: T[]): Promise<U>;
187 (key: string, cursor: number, arg1: T[]): Promise<U>;
188 }
189
190 type Command = _Command;
191
192 interface Commands {
193 bitcount(key: KeyType, callback: Callback<number>): void;
194 bitcount(key: KeyType, start: number, end: number, callback: (err: Error, res: number) => void): void;
195 bitcount(key: KeyType): Promise<number>;
196 bitcount(key: KeyType, start: number, end: number): Promise<number>;
197
198 get(key: KeyType, callback: Callback<string | null>): void;
199 get(key: KeyType): Promise<string | null>;
200
201 getBuffer(key: KeyType, callback: Callback<Buffer>): void;
202 getBuffer(key: KeyType): Promise<Buffer>;
203
204 set(
205 key: KeyType,
206 value: ValueType,
207 expiryMode?: string | any[],
208 time?: number | string,
209 setMode?: number | string,
210 ): Promise<Ok>;
211
212 set(key: KeyType, value: ValueType, callback: Callback<Ok>): void;
213 set(key: KeyType, value: ValueType, setMode: string | any[], callback: Callback<Ok>): void;
214 set(key: KeyType, value: ValueType, expiryMode: string, time: number | string, callback: Callback<Ok>): void;
215 set(
216 key: KeyType,
217 value: ValueType,
218 expiryMode: string,
219 time: number | string,
220 setMode: number | string,
221 callback: Callback<Ok>,
222 ): void;
223
224 setBuffer(
225 key: KeyType,
226 value: ValueType,
227 expiryMode?: string | any[],
228 time?: number | string,
229 setMode?: number | string,
230 ): Promise<Buffer>;
231
232 setBuffer(key: KeyType, value: ValueType, callback: Callback<Buffer>): void;
233 setBuffer(key: KeyType, value: ValueType, setMode: string, callback: Callback<Buffer>): void;
234 setBuffer(key: KeyType, value: ValueType, expiryMode: string, time: number, callback: Callback<Buffer>): void;
235 setBuffer(
236 key: KeyType,
237 value: ValueType,
238 expiryMode: string,
239 time: number | string,
240 setMode: number | string,
241 callback: Callback<Buffer>,
242 ): void;
243
244 setnx(key: KeyType, value: ValueType, callback: Callback<BooleanResponse>): void;
245 setnx(key: KeyType, value: ValueType): Promise<BooleanResponse>;
246
247 setex(key: KeyType, seconds: number, value: ValueType, callback: Callback<Ok>): void;
248 setex(key: KeyType, seconds: number, value: ValueType): Promise<Ok>;
249
250 psetex(key: KeyType, milliseconds: number, value: ValueType, callback: Callback<Ok>): void;
251 psetex(key: KeyType, milliseconds: number, value: ValueType): Promise<Ok>;
252
253 append(key: KeyType, value: ValueType, callback: Callback<number>): void;
254 append(key: KeyType, value: ValueType): Promise<number>;
255
256 strlen(key: KeyType, callback: Callback<number>): void;
257 strlen(key: KeyType): Promise<number>;
258
259 del: OverloadedListCommand<KeyType, number>;
260
261 unlink: OverloadedListCommand<KeyType, number>;
262
263 exists(...keys: KeyType[]): Promise<number>;
264 exists(key: KeyType, callback: Callback<number>): void;
265
266 setbit(key: KeyType, offset: number, value: ValueType, callback: Callback<number>): void;
267 setbit(key: KeyType, offset: number, value: ValueType): Promise<number>;
268
269 getbit(key: KeyType, offset: number, callback: Callback<number>): void;
270 getbit(key: KeyType, offset: number): Promise<number>;
271
272 setrange(key: KeyType, offset: number, value: ValueType, callback: Callback<number>): void;
273 setrange(key: KeyType, offset: number, value: ValueType): Promise<number>;
274
275 getrange(key: KeyType, start: number, end: number, callback: Callback<string>): void;
276 getrange(key: KeyType, start: number, end: number): Promise<string>;
277
278 substr(key: KeyType, start: number, end: number, callback: Callback<string>): void;
279 substr(key: KeyType, start: number, end: number): Promise<string>;
280
281 incr(key: KeyType, callback: Callback<number>): void;
282 incr(key: KeyType): Promise<number>;
283
284 decr(key: KeyType, callback: Callback<number>): void;
285 decr(key: KeyType): Promise<number>;
286
287 mget: OverloadedListCommand<KeyType, Array<string | null>>;
288
289 rpush: OverloadedKeyCommand<ValueType, number>;
290 rpushBuffer: OverloadedKeyCommand<Buffer, number>;
291
292 lpush: OverloadedKeyCommand<ValueType, number>;
293 lpushBuffer: OverloadedKeyCommand<Buffer, number>;
294
295 rpushx: OverloadedKeyCommand<ValueType, number>;
296
297 lpushx: OverloadedKeyCommand<ValueType, number>;
298
299 linsert(
300 key: KeyType,
301 direction: 'BEFORE' | 'AFTER',
302 pivot: string,
303 value: ValueType,
304 callback: Callback<number>,
305 ): void;
306 linsert(key: KeyType, direction: 'BEFORE' | 'AFTER', pivot: string, value: ValueType): Promise<number>;
307
308 rpop(key: KeyType, callback: Callback<string>): void;
309 rpop(key: KeyType): Promise<string>;
310
311 lpop(key: KeyType, callback: Callback<string>): void;
312 lpop(key: KeyType): Promise<string>;
313
314 lpopBuffer(key: KeyType, callback: Callback<Buffer>): void;
315 lpopBuffer(key: KeyType): Promise<Buffer>;
316
317 brpop: OverloadedBlockingListCommand<KeyType, [string, string]>;
318
319 blpop: OverloadedBlockingListCommand<KeyType, [string, string]>;
320
321 brpoplpush(source: string, destination: string, timeout: number, callback: Callback<string>): void;
322 brpoplpush(source: string, destination: string, timeout: number): Promise<string>;
323
324 llen(key: KeyType, callback: Callback<number>): void;
325 llen(key: KeyType): Promise<number>;
326
327 lindex(key: KeyType, index: number, callback: Callback<string>): void;
328 lindex(key: KeyType, index: number): Promise<string>;
329
330 lset(key: KeyType, index: number, value: ValueType, callback: Callback<Ok>): void;
331 lset(key: KeyType, index: number, value: ValueType): Promise<Ok>;
332
333 lrange(key: KeyType, start: number, stop: number, callback: Callback<string[]>): void;
334 lrange(key: KeyType, start: number, stop: number): Promise<string[]>;
335
336 lrangeBuffer(key: KeyType, start: number, stop: number, callback: Callback<Buffer[]>): void;
337 lrangeBuffer(key: KeyType, start: number, stop: number): Promise<Buffer[]>;
338
339 ltrim(key: KeyType, start: number, stop: number, callback: Callback<Ok>): void;
340 ltrim(key: KeyType, start: number, stop: number): Promise<Ok>;
341
342 lrem(key: KeyType, count: number, value: ValueType, callback: Callback<number>): void;
343 lrem(key: KeyType, count: number, value: ValueType): Promise<number>;
344
345 rpoplpush(source: string, destination: string, callback: Callback<string>): void;
346 rpoplpush(source: string, destination: string): Promise<string>;
347
348 rpoplpushBuffer(source: string, destination: string, callback: Callback<Buffer>): void;
349 rpoplpushBuffer(source: string, destination: string): Promise<Buffer>;
350
351 sadd: OverloadedKeyCommand<ValueType, number>;
352
353 srem: OverloadedKeyCommand<ValueType, number>;
354
355 smove(source: string, destination: string, member: string, callback: Callback<BooleanResponse>): void;
356 smove(source: string, destination: string, member: string): Promise<BooleanResponse>;
357
358 sismember(key: KeyType, member: string, callback: Callback<BooleanResponse>): void;
359 sismember(key: KeyType, member: string): Promise<BooleanResponse>;
360
361 scard(key: KeyType, callback: Callback<number>): void;
362 scard(key: KeyType): Promise<number>;
363
364 spop(key: KeyType, callback: Callback<string | null>): void;
365 spop(key: KeyType): Promise<string | null>;
366 spop(key: KeyType, count: number, callback: Callback<string[]>): void;
367 spop(key: KeyType, count: number): Promise<string[]>;
368
369 srandmember(key: KeyType, callback: Callback<string | null>): void;
370 srandmember(key: KeyType): Promise<string | null>;
371 srandmember(key: KeyType, count: number, callback: Callback<string[]>): void;
372 srandmember(key: KeyType, count: number): Promise<string[]>;
373
374 sinter: OverloadedListCommand<KeyType, string[]>;
375
376 sinterstore: OverloadedKeyCommand<KeyType, number>;
377
378 sunion: OverloadedListCommand<KeyType, string[]>;
379
380 sunionstore: OverloadedKeyCommand<KeyType, number>;
381
382 sdiff: OverloadedListCommand<KeyType, string[]>;
383
384 sdiffstore: OverloadedKeyCommand<KeyType, number>;
385
386 smembers(key: KeyType, callback: Callback<string[]>): void;
387 smembers(key: KeyType): Promise<string[]>;
388
389 zadd: OverloadedKeyCommand<KeyType | number, number | string>;
390
391 zaddBuffer(key: KeyType, score1: number, member1: Buffer, callback: Callback<string | number>): void;
392 zaddBuffer(key: KeyType, score1: number, member1: Buffer): Promise<string | number>;
393
394 zincrby(key: KeyType, increment: number, member: string, callback: Callback<string>): void;
395 zincrby(key: KeyType, increment: number, member: string): Promise<string>;
396
397 zpopmin(key: KeyType, callback: Callback<string[]>): void;
398 zpopmin(key: KeyType, count: number, callback: Callback<string[]>): void;
399 zpopmin(key: KeyType, count?: number): Promise<string[]>;
400
401 zpopmax(key: KeyType, callback: Callback<string[]>): void;
402 zpopmax(key: KeyType, count: number, callback: Callback<string[]>): void;
403 zpopmax(key: KeyType, count?: number): Promise<string[]>;
404
405 zrem: OverloadedKeyCommand<ValueType, number>;
406
407 zremrangebyscore(key: KeyType, min: number | string, max: number | string, callback: Callback<number>): void;
408 zremrangebyscore(key: KeyType, min: number | string, max: number | string): Promise<number>;
409
410 zremrangebyrank(key: KeyType, start: number, stop: number, callback: Callback<number>): void;
411 zremrangebyrank(key: KeyType, start: number, stop: number): Promise<number>;
412
413 zremrangebylex(
414 key: KeyType,
415 min: string,
416 max: string,
417 ): Promise<number>;
418 zremrangebylex(
419 key: KeyType,
420 min: string,
421 max: string,
422 callback: Callback<number>
423 ): void;
424
425 zunionstore: OverloadedKeyCommand<KeyType | number, number>;
426
427 zinterstore: OverloadedKeyCommand<KeyType | number, number>;
428
429 zrange(key: KeyType, start: number, stop: number, callback: Callback<string[]>): void;
430 zrange(key: KeyType, start: number, stop: number, withScores: 'WITHSCORES', callback: Callback<string[]>): void;
431 zrange(key: KeyType, start: number, stop: number, withScores?: 'WITHSCORES'): Promise<string[]>;
432
433 zrevrange(key: KeyType, start: number, stop: number, callback: Callback<string[]>): void;
434 zrevrange(
435 key: KeyType,
436 start: number,
437 stop: number,
438 withScores: 'WITHSCORES',
439 callback: Callback<string[]>,
440 ): void;
441 zrevrange(key: KeyType, start: number, stop: number, withScores?: 'WITHSCORES'): Promise<string[]>;
442
443 zrangebyscore(
444 key: KeyType,
445 min: number | string,
446 max: number | string,
447 withScores?: 'WITHSCORES',
448 ): Promise<string[]>;
449 zrangebyscore(
450 key: KeyType,
451 min: number | string,
452 max: number | string,
453 withScores: 'WITHSCORES',
454 limit: 'LIMIT',
455 offset: number,
456 count: number,
457 ): Promise<string[]>;
458 zrangebyscore(
459 key: KeyType,
460 min: number | string,
461 max: number | string,
462 limit: 'LIMIT',
463 offset: number,
464 count: number,
465 ): Promise<string[]>;
466 zrangebyscore(key: KeyType, min: number | string, max: number | string, callback: Callback<string[]>): void;
467 zrangebyscore(
468 key: KeyType,
469 min: number | string,
470 max: number | string,
471 withScores: 'WITHSCORES',
472 callback: Callback<string[]>,
473 ): void;
474 zrangebyscore(
475 key: KeyType,
476 min: number | string,
477 max: number | string,
478 withScores: 'WITHSCORES',
479 limit: 'LIMIT',
480 offset: number,
481 count: number,
482 callback: Callback<string[]>,
483 ): void;
484 zrangebyscore(
485 key: KeyType,
486 min: number | string,
487 max: number | string,
488 limit: 'LIMIT',
489 offset: number,
490 count: number,
491 callback: Callback<string[]>,
492 ): void;
493
494 zrevrangebyscore(
495 key: KeyType,
496 max: number | string,
497 min: number | string,
498 withScores?: 'WITHSCORES',
499 ): Promise<string[]>;
500 zrevrangebyscore(
501 key: KeyType,
502 max: number | string,
503 min: number | string,
504 withScores: 'WITHSCORES',
505 limit: 'LIMIT',
506 offset: number,
507 count: number,
508 ): Promise<string[]>;
509 zrevrangebyscore(
510 key: KeyType,
511 max: number | string,
512 min: number | string,
513 limit: 'LIMIT',
514 offset: number,
515 count: number,
516 ): Promise<string[]>;
517 zrevrangebyscore(key: KeyType, max: number | string, min: number | string, callback: Callback<string[]>): void;
518 zrevrangebyscore(
519 key: KeyType,
520 max: number | string,
521 min: number | string,
522 withScores: 'WITHSCORES',
523 callback: Callback<string[]>,
524 ): void;
525 zrevrangebyscore(
526 key: KeyType,
527 max: number | string,
528 min: number | string,
529 withScores: 'WITHSCORES',
530 limit: 'LIMIT',
531 offset: number,
532 count: number,
533 callback: Callback<string[]>,
534 ): void;
535 zrevrangebyscore(
536 key: KeyType,
537 max: number | string,
538 min: number | string,
539 limit: 'LIMIT',
540 offset: number,
541 count: number,
542 callback: Callback<string[]>,
543 ): void;
544
545 zrangebylex(
546 key: KeyType,
547 min: string,
548 max: string,
549 ): Promise<string[]>;
550 zrangebylex(
551 key: KeyType,
552 min: string,
553 max: string,
554 limit: 'LIMIT',
555 offset: number,
556 count: number,
557 ): Promise<string[]>;
558 zrangebylex(
559 key: KeyType,
560 min: string,
561 max: string,
562 callback: Callback<string[]>,
563 ): void;
564 zrangebylex(
565 key: KeyType,
566 min: string,
567 max: string,
568 limit: 'LIMIT',
569 offset: number,
570 count: number,
571 callback: Callback<string[]>,
572 ): void;
573
574 zrevrangebylex(
575 key: KeyType,
576 min: string,
577 max: string,
578 ): Promise<string[]>;
579 zrevrangebylex(
580 key: KeyType,
581 min: string,
582 max: string,
583 limit: 'LIMIT',
584 offset: number,
585 count: number,
586 ): Promise<string[]>;
587 zrevrangebylex(
588 key: KeyType,
589 min: string,
590 max: string,
591 callback: Callback<string[]>,
592 ): void;
593 zrevrangebylex(
594 key: KeyType,
595 min: string,
596 max: string,
597 limit: 'LIMIT',
598 offset: number,
599 count: number,
600 callback: Callback<string[]>,
601 ): void;
602
603 zcount(key: KeyType, min: number | string, max: number | string, callback: Callback<number>): void;
604 zcount(key: KeyType, min: number | string, max: number | string): Promise<number>;
605
606 zcard(key: KeyType, callback: Callback<number>): void;
607 zcard(key: KeyType): Promise<number>;
608
609 zscore(key: KeyType, member: string, callback: Callback<string>): void;
610 zscore(key: KeyType, member: string): Promise<string>;
611
612 zrank(key: KeyType, member: string, callback: Callback<number | null>): void;
613 zrank(key: KeyType, member: string): Promise<number | null>;
614
615 zrevrank(key: KeyType, member: string, callback: Callback<number | null>): void;
616 zrevrank(key: KeyType, member: string): Promise<number | null>;
617
618 hset(key: KeyType, field: string, value: ValueType, callback: Callback<BooleanResponse>): void;
619 hset(key: KeyType, field: string, value: ValueType): Promise<BooleanResponse>;
620 hsetBuffer(key: KeyType, field: string, value: ValueType, callback: Callback<BooleanResponse>): void;
621 hsetBuffer(key: KeyType, field: string, value: ValueType): Promise<Buffer>;
622
623 hsetnx(key: KeyType, field: string, value: ValueType, callback: Callback<BooleanResponse>): void;
624 hsetnx(key: KeyType, field: string, value: ValueType): Promise<BooleanResponse>;
625
626 hget(key: KeyType, field: string, callback: Callback<string | null>): void;
627 hget(key: KeyType, field: string): Promise<string | null>;
628 hgetBuffer(key: KeyType, field: string, callback: Callback<Buffer>): void;
629 hgetBuffer(key: KeyType, field: string): Promise<Buffer>;
630
631 hmset: OverloadedKeyedHashCommand<ValueType, Ok>;
632
633 hmget: OverloadedKeyCommand<KeyType, Array<string | null>>;
634
635 hincrby(key: KeyType, field: string, increment: number, callback: Callback<number>): void;
636 hincrby(key: KeyType, field: string, increment: number): Promise<number>;
637
638 hincrbyfloat(key: KeyType, field: string, increment: number, callback: Callback<number>): void;
639 hincrbyfloat(key: KeyType, field: string, increment: number): Promise<number>;
640
641 hdel: OverloadedKeyCommand<KeyType, number>;
642
643 hlen(key: KeyType, callback: Callback<number>): void;
644 hlen(key: KeyType): Promise<number>;
645
646 hkeys(key: KeyType, callback: Callback<string[]>): void;
647 hkeys(key: KeyType): Promise<string[]>;
648
649 hvals(key: KeyType, callback: Callback<string[]>): void;
650 hvals(key: KeyType): Promise<string[]>;
651
652 hgetall(key: KeyType, callback: Callback<Record<string, string>>): void;
653 hgetall(key: KeyType): Promise<Record<string, string>>;
654
655 hexists(key: KeyType, field: string, callback: Callback<BooleanResponse>): void;
656 hexists(key: KeyType, field: string): Promise<BooleanResponse>;
657
658 incrby(key: KeyType, increment: number, callback: Callback<number>): void;
659 incrby(key: KeyType, increment: number): Promise<number>;
660
661 incrbyfloat(key: KeyType, increment: number, callback: Callback<number>): void;
662 incrbyfloat(key: KeyType, increment: number): Promise<number>;
663
664 decrby(key: KeyType, decrement: number, callback: Callback<number>): void;
665 decrby(key: KeyType, decrement: number): Promise<number>;
666
667 getset(key: KeyType, value: ValueType, callback: Callback<string | null>): void;
668 getset(key: KeyType, value: ValueType): Promise<string | null>;
669
670 mset: OverloadedHashCommand<ValueType, Ok>;
671 msetnx: OverloadedHashCommand<ValueType, BooleanResponse>;
672
673 randomkey(callback: Callback<string>): void;
674 randomkey(): Promise<string>;
675
676 select(index: number, callback: Callback<Ok>): void;
677 select(index: number): Promise<Ok>;
678
679 move(key: KeyType, db: string, callback: Callback<BooleanResponse>): void;
680 move(key: KeyType, db: string): Promise<BooleanResponse>;
681
682 rename(key: KeyType, newkey: KeyType, callback: Callback<Ok>): void;
683 rename(key: KeyType, newkey: KeyType): Promise<Ok>;
684
685 renamenx(key: KeyType, newkey: KeyType, callback: Callback<BooleanResponse>): void;
686 renamenx(key: KeyType, newkey: KeyType): Promise<BooleanResponse>;
687
688 expire(key: KeyType, seconds: number, callback: Callback<BooleanResponse>): void;
689 expire(key: KeyType, seconds: number): Promise<BooleanResponse>;
690
691 pexpire(key: KeyType, milliseconds: number, callback: Callback<BooleanResponse>): void;
692 pexpire(key: KeyType, milliseconds: number): Promise<BooleanResponse>;
693
694 expireat(key: KeyType, timestamp: number, callback: Callback<BooleanResponse>): void;
695 expireat(key: KeyType, timestamp: number): Promise<BooleanResponse>;
696
697 pexpireat(key: KeyType, millisecondsTimestamp: number, callback: Callback<BooleanResponse>): void;
698 pexpireat(key: KeyType, millisecondsTimestamp: number): Promise<BooleanResponse>;
699
700 keys(pattern: string, callback: Callback<string[]>): void;
701 keys(pattern: string): Promise<string[]>;
702
703 dbsize(callback: Callback<number>): void;
704 dbsize(): Promise<number>;
705
706 auth(password: string, callback: Callback<string>): void;
707 auth(password: string): Promise<string>;
708
709 ping(callback: Callback<string>): void;
710 ping(message: string, callback: Callback<string>): void;
711 ping(message?: string): Promise<string>;
712
713 echo(message: string, callback: Callback<string>): void;
714 echo(message: string): Promise<string>;
715
716 save(callback: Callback<string>): void;
717 save(): Promise<string>;
718
719 bgsave(callback: Callback<string>): void;
720 bgsave(): Promise<string>;
721
722 bgrewriteaof(callback: Callback<string>): void;
723 bgrewriteaof(): Promise<string>;
724
725 shutdown(save: 'SAVE' | 'NOSAVE', callback: Callback<never>): void;
726 shutdown(save: 'SAVE' | 'NOSAVE'): Promise<never>;
727
728 lastsave(callback: Callback<number>): void;
729 lastsave(): Promise<number>;
730
731 type(key: KeyType, callback: Callback<string>): void;
732 type(key: KeyType): Promise<string>;
733
734 multi(commands?: string[][], options?: MultiOptions): Pipeline;
735 multi(options: { pipeline: false }): Promise<Ok>;
736
737 exec(callback: Callback<Array<[Error | null, string]>>): void;
738 exec(): Promise<Array<[Error | null, string]>>;
739
740 discard(callback: Callback<Ok>): void;
741 discard(): Promise<Ok>;
742
743 sync(callback: Callback<any>): void;
744 sync(): Promise<any>;
745
746 flushdb(callback: Callback<Ok>): void;
747 flushdb(): Promise<Ok>;
748
749 flushall(callback: Callback<Ok>): void;
750 flushall(): Promise<Ok>;
751
752 sort: OverloadedListCommand<KeyType | number, string[] | number>;
753
754 info(callback: Callback<string>): void;
755 info(section: string, callback: Callback<string>): void;
756 info(section?: string): Promise<string>;
757
758 time(callback: Callback<[string, string]>): void;
759 time(): Promise<[string, string]>;
760
761 monitor(callback: Callback<EventEmitter>): void;
762 monitor(): Promise<EventEmitter>;
763
764 ttl(key: KeyType, callback: Callback<number>): void;
765 ttl(key: KeyType): Promise<number>;
766
767 pttl(key: KeyType, callback: Callback<number>): void;
768 pttl(key: KeyType): Promise<number>;
769
770 persist(key: KeyType, callback: Callback<BooleanResponse>): void;
771 persist(key: KeyType): Promise<BooleanResponse>;
772
773 slaveof(host: string, port: number, callback: Callback<string>): void;
774 slaveof(host: string, port: number): Promise<string>;
775
776 debug: OverloadedSubCommand<ValueType, any>;
777
778 config(op: 'GET', cfg: string): Promise<string[]>;
779 config(op: 'GET', cfg: string, callback: Callback<string[]>): void;
780 config(op: 'REWRITE' | 'RESETSTAT'): Promise<Ok>;
781 config(op: 'REWRITE' | 'RESETSTAT', callback: Callback<Ok>): void;
782 config(op: 'SET', key: string, value: ValueType): Promise<Ok>;
783 config(op: 'SET', key: string, value: ValueType, callback: Callback<Ok>): void;
784
785 subscribe: OverloadedListCommand<string, number>;
786
787 unsubscribe: OverloadedCommand<string, number>;
788
789 psubscribe: OverloadedListCommand<string, number>;
790
791 punsubscribe: OverloadedCommand<string, number>;
792
793 publish(channel: string, message: string, callback: Callback<number>): void;
794 publish(channel: string, message: string): Promise<number>;
795
796 publishBuffer(channel: string, message: Buffer): Promise<number>;
797
798 watch: OverloadedListCommand<KeyType, Ok>;
799
800 unwatch(callback: Callback<string>): void;
801 unwatch(): Promise<string>;
802
803 cluster: OverloadedSubCommand<ValueType, any>;
804
805 restore: OverloadedListCommand<ValueType, Ok>;
806
807 migrate: OverloadedListCommand<ValueType, Ok | 'NOKEY'>;
808
809 dump(key: KeyType, callback: Callback<string>): void;
810 dump(key: KeyType): Promise<string>;
811
812 object: OverloadedListCommand<ValueType, any>;
813
814 client: OverloadedSubCommand<ValueType, any>;
815
816 eval: OverloadedEvalCommand<ValueType, any>;
817
818 evalsha: OverloadedEvalCommand<ValueType, any>;
819
820 script: OverloadedSubCommand<ValueType, any>;
821
822 quit(callback: Callback<Ok>): void;
823 quit(): Promise<Ok>;
824
825 scan(cursor: number | string, matchOption: 'match' | 'MATCH', pattern: string): Promise<[string, string[]]>;
826 scan(
827 cursor: number | string,
828 matchOption: 'match' | 'MATCH',
829 pattern: string,
830 callback: Callback<[string, string[]]>,
831 ): void;
832 scan(cursor: number | string, countOption: 'count' | 'COUNT', count: number): Promise<[string, string[]]>;
833 scan(
834 cursor: number | string,
835 countOption: 'count' | 'COUNT',
836 count: number,
837 callback: Callback<[string, string[]]>,
838 ): void;
839
840 scan(
841 cursor: number | string,
842 matchOption: 'match' | 'MATCH',
843 pattern: string,
844 countOption: 'count' | 'COUNT',
845 count: number,
846 ): Promise<[string, string[]]>;
847 scan(
848 cursor: number | string,
849 matchOption: 'match' | 'MATCH',
850 pattern: string,
851 countOption: 'count' | 'COUNT',
852 count: number,
853 callback: Callback<[string, string[]]>,
854 ): void;
855 scan(
856 cursor: number | string,
857 countOption: 'count' | 'COUNT',
858 count: number,
859 matchOption: 'match' | 'MATCH',
860 pattern: string,
861 ): Promise<[string, string[]]>;
862 scan(
863 cursor: number | string,
864 countOption: 'count' | 'COUNT',
865 count: number,
866 matchOption: 'match' | 'MATCH',
867 pattern: string,
868 callback: Callback<[string, string[]]>,
869 ): void;
870
871 sscan: OverloadedKeyCommand<ValueType, [string, string[]]>;
872
873 hscan: OverloadedKeyCommand<ValueType, [string, string[]]>;
874
875 zscan: OverloadedKeyCommand<ValueType, [string, string[]]>;
876
877 pfmerge: OverloadedKeyCommand<KeyType, Ok>;
878
879 pfadd: OverloadedKeyCommand<string, number>;
880
881 pfcount: OverloadedListCommand<KeyType, number>;
882
883 pipeline(commands?: string[][]): Pipeline;
884
885 scanStream(options?: ScanStreamOption): Readable;
886 sscanStream(key: KeyType, options?: ScanStreamOption): Readable;
887 hscanStream(key: KeyType, options?: ScanStreamOption): Readable;
888 zscanStream(key: KeyType, options?: ScanStreamOption): Readable;
889
890 xack: OverloadedKeyCommand<ValueType, number>;
891
892 xadd: OverloadedKeyCommand<ValueType, string>;
893
894 xclaim: OverloadedKeyCommand<ValueType, Array<[string, string[]]>>;
895
896 xdel: OverloadedKeyCommand<string, number>;
897
898 xgroup: OverloadedSubCommand<ValueType, Ok>;
899
900 xinfo: OverloadedSubCommand<ValueType, any>;
901
902 xlen(key: KeyType): Promise<number>;
903 xlen(key: KeyType, callback: Callback<number>): void;
904
905 xpending: OverloadedKeyCommand<ValueType, any>;
906
907 xrange: OverloadedKeyCommand<ValueType, Array<[string, string[]]>>;
908
909 xread: OverloadedListCommand<ValueType, Array<[string, string[]]>>;
910
911 xreadgroup: OverloadedKeyCommand<ValueType, Array<[string, string[]]>>;
912
913 xrevrange: OverloadedKeyCommand<ValueType, Array<[string, string[]]>>;
914
915 xtrim: OverloadedKeyCommand<ValueType, number>;
916 }
917
918 interface Redis extends EventEmitter, Commander, Commands {
919 Promise: typeof Promise;
920 options: RedisOptions;
921 status: string;
922 connect(callback?: () => void): Promise<void>;
923 disconnect(): void;
924 duplicate(): Redis;
925
926 send_command(command: string, ...args: ValueType[]): Promise<any>;
927 }
928
929 interface Pipeline {
930 readonly redis: Redis;
931 readonly isCluster: boolean;
932 readonly options: RedisOptions;
933 readonly length: number;
934
935 bitcount(key: KeyType, callback?: Callback<number>): Pipeline;
936 bitcount(key: KeyType, start: number, end: number, callback?: Callback<number>): Pipeline;
937
938 get(key: KeyType, callback?: Callback<string>): Pipeline;
939 getBuffer(key: KeyType, callback?: Callback<Buffer>): Pipeline;
940
941 set(key: KeyType, value: ValueType, callback?: Callback<string>): Pipeline;
942 set(key: KeyType, value: ValueType, setMode: string, callback?: Callback<string>): Pipeline;
943 set(key: KeyType, value: ValueType, expiryMode: string, time: number, callback?: Callback<string>): Pipeline;
944 set(
945 key: KeyType,
946 value: ValueType,
947 expiryMode: string,
948 time: number,
949 setMode: string,
950 callback?: Callback<string>,
951 ): Pipeline;
952
953 setBuffer(key: KeyType, value: ValueType, callback?: Callback<Buffer>): Pipeline;
954 setBuffer(key: KeyType, value: ValueType, setMode: string, callback?: Callback<Buffer>): Pipeline;
955 setBuffer(
956 key: KeyType,
957 value: ValueType,
958 expiryMode: string,
959 time: number,
960 callback?: Callback<Buffer>,
961 ): Pipeline;
962 setBuffer(
963 key: KeyType,
964 value: ValueType,
965 expiryMode: string,
966 time: number,
967 setMode: string,
968 callback?: Callback<Buffer>,
969 ): Pipeline;
970
971 setnx(key: KeyType, value: ValueType, callback?: Callback<BooleanResponse>): Pipeline;
972
973 setex(key: KeyType, seconds: number, value: ValueType, callback?: Callback<Ok>): Pipeline;
974
975 psetex(key: KeyType, milliseconds: number, value: ValueType, callback?: Callback<Ok>): Pipeline;
976
977 append(key: KeyType, value: ValueType, callback?: Callback<number>): Pipeline;
978
979 strlen(key: KeyType, callback?: Callback<number>): Pipeline;
980
981 del(...keys: KeyType[]): Pipeline;
982
983 unlink(...keys: KeyType[]): Pipeline;
984
985 exists(...keys: KeyType[]): Pipeline;
986
987 setbit(key: KeyType, offset: number, value: ValueType, callback?: Callback<number>): Pipeline;
988
989 getbit(key: KeyType, offset: number, callback?: Callback<number>): Pipeline;
990
991 setrange(key: KeyType, offset: number, value: ValueType, callback?: Callback<number>): Pipeline;
992
993 getrange(key: KeyType, start: number, end: number, callback?: Callback<string>): Pipeline;
994
995 substr(key: KeyType, start: number, end: number, callback?: Callback<string>): Pipeline;
996
997 incr(key: KeyType, callback?: Callback<number>): Pipeline;
998
999 decr(key: KeyType, callback?: Callback<number>): Pipeline;
1000
1001 mget(...keys: KeyType[]): Pipeline;
1002
1003 rpush(key: KeyType, ...values: ValueType[]): Pipeline;
1004
1005 rpushBuffer(key: string, ...values: Buffer[]): Pipeline;
1006
1007 lpush(key: KeyType, ...values: ValueType[]): Pipeline;
1008
1009 rpushx(key: KeyType, value: ValueType, callback?: Callback<number>): Pipeline;
1010
1011 lpushx(key: KeyType, value: ValueType, callback?: Callback<number>): Pipeline;
1012
1013 linsert(
1014 key: KeyType,
1015 direction: 'BEFORE' | 'AFTER',
1016 pivot: string,
1017 value: ValueType,
1018 callback?: Callback<number>,
1019 ): Pipeline;
1020
1021 rpop(key: KeyType, callback?: Callback<string>): Pipeline;
1022
1023 lpop(key: KeyType, callback?: Callback<string>): Pipeline;
1024
1025 lpopBuffer(key: KeyType, callback?: Callback<Buffer>): Pipeline;
1026
1027 brpop(...keys: KeyType[]): Pipeline;
1028
1029 blpop(...keys: KeyType[]): Pipeline;
1030
1031 brpoplpush(source: string, destination: string, timeout: number, callback?: Callback<string>): Pipeline;
1032
1033 llen(key: KeyType, callback?: Callback<number>): Pipeline;
1034
1035 lindex(key: KeyType, index: number, callback?: Callback<string>): Pipeline;
1036
1037 lset(key: KeyType, index: number, value: ValueType, callback?: Callback<Ok>): Pipeline;
1038
1039 lrange(key: KeyType, start: number, stop: number, callback?: Callback<string[]>): Pipeline;
1040
1041 lrangeBuffer(key: KeyType, start: number, stop: number, callback?: Callback<Buffer[]>): Pipeline;
1042
1043 ltrim(key: KeyType, start: number, stop: number, callback?: Callback<Ok>): Pipeline;
1044
1045 lrem(key: KeyType, count: number, value: ValueType, callback?: Callback<number>): Pipeline;
1046
1047 rpoplpush(source: string, destination: string, callback?: Callback<string>): Pipeline;
1048
1049 sadd(key: KeyType, ...members: ValueType[]): Pipeline;
1050
1051 srem(key: KeyType, ...members: ValueType[]): Pipeline;
1052
1053 smove(source: string, destination: string, member: string, callback?: Callback<string>): Pipeline;
1054
1055 sismember(key: KeyType, member: string, callback?: Callback<BooleanResponse>): Pipeline;
1056
1057 scard(key: KeyType, callback?: Callback<number>): Pipeline;
1058
1059 spop(key: KeyType, callback?: Callback<string | null>): Pipeline;
1060 spop(key: KeyType, count: number, callback?: Callback<string[]>): Pipeline;
1061
1062 srandmember(key: KeyType, callback?: Callback<string | null>): Pipeline;
1063 srandmember(key: KeyType, count: number, callback?: Callback<string[]>): Pipeline;
1064
1065 sinter(...keys: KeyType[]): Pipeline;
1066
1067 sinterstore(destination: string, ...keys: KeyType[]): Pipeline;
1068
1069 sunion(...keys: KeyType[]): Pipeline;
1070
1071 sunionstore(destination: string, ...keys: KeyType[]): Pipeline;
1072
1073 sdiff(...keys: KeyType[]): Pipeline;
1074
1075 sdiffstore(destination: string, ...keys: KeyType[]): Pipeline;
1076
1077 smembers(key: KeyType, callback?: Callback<string[]>): Pipeline;
1078
1079 zadd(key: KeyType, ...args: string[]): Pipeline;
1080
1081 zincrby(key: KeyType, increment: number, member: string, callback?: Callback<string>): Pipeline;
1082
1083 zrem(key: KeyType, ...members: ValueType[]): Pipeline;
1084
1085 zremrangebyscore(
1086 key: KeyType,
1087 min: number | string,
1088 max: number | string,
1089 callback?: Callback<number>,
1090 ): Pipeline;
1091
1092 zremrangebyrank(key: KeyType, start: number, stop: number, callback?: Callback<number>): Pipeline;
1093
1094 zremrangebylex(
1095 key: KeyType,
1096 min: string,
1097 max: string,
1098 callback?: Callback<number>,
1099 ): Pipeline;
1100
1101 zunionstore(destination: string, numkeys: number, key: KeyType, ...args: string[]): Pipeline;
1102
1103 zinterstore(destination: string, numkeys: number, key: KeyType, ...args: string[]): Pipeline;
1104
1105 zrange(key: KeyType, start: number, stop: number, callback?: Callback<string[]>): Pipeline;
1106 zrange(
1107 key: KeyType,
1108 start: number,
1109 stop: number,
1110 withScores: 'WITHSCORES',
1111 callback?: Callback<string[]>,
1112 ): Pipeline;
1113
1114 zrevrange(key: KeyType, start: number, stop: number, callback?: Callback<string[]>): Pipeline;
1115 zrevrange(
1116 key: KeyType,
1117 start: number,
1118 stop: number,
1119 withScores: 'WITHSCORES',
1120 callback?: Callback<string[]>,
1121 ): Pipeline;
1122
1123 zrangebyscore(key: KeyType, min: number | string, max: number | string, ...args: string[]): Pipeline;
1124
1125 zrevrangebyscore(key: KeyType, max: number | string, min: number | string, ...args: string[]): Pipeline;
1126
1127 zrangebylex(
1128 key: KeyType,
1129 min: string,
1130 max: string,
1131 callback?: Callback<string[]>,
1132 ): Pipeline;
1133 zrangebylex(
1134 key: KeyType,
1135 min: string,
1136 max: string,
1137 limit: 'LIMIT',
1138 offset: number,
1139 count: number,
1140 callback?: Callback<string[]>,
1141 ): Pipeline;
1142 zrevrangebylex(
1143 key: KeyType,
1144 min: string,
1145 max: string,
1146 callback?: Callback<string[]>,
1147 ): Pipeline;
1148 zrevrangebylex(
1149 key: KeyType,
1150 min: string,
1151 max: string,
1152 limit: 'LIMIT',
1153 offset: number,
1154 count: number,
1155 callback?: Callback<string[]>,
1156 ): Pipeline;
1157
1158 zcount(key: KeyType, min: number | string, max: number | string, callback?: Callback<number>): Pipeline;
1159
1160 zcard(key: KeyType, callback?: Callback<number>): Pipeline;
1161
1162 zscore(key: KeyType, member: string, callback?: Callback<number>): Pipeline;
1163
1164 zrank(key: KeyType, member: string, callback?: Callback<number>): Pipeline;
1165
1166 zrevrank(key: KeyType, member: string, callback?: Callback<number>): Pipeline;
1167
1168 hset(key: KeyType, field: string, value: ValueType, callback?: Callback<BooleanResponse>): Pipeline;
1169 hsetBuffer(key: KeyType, field: string, value: ValueType, callback?: Callback<Buffer>): Pipeline;
1170
1171 hsetnx(key: KeyType, field: string, value: ValueType, callback?: Callback<BooleanResponse>): Pipeline;
1172
1173 hget(key: KeyType, field: string, callback?: Callback<string | string>): Pipeline;
1174 hgetBuffer(key: KeyType, field: string, callback?: Callback<Buffer>): Pipeline;
1175
1176 hmset(key: KeyType, ...args: ValueType[]): Pipeline;
1177 hmset(key: KeyType, data: object | Map<string, any>, callback?: Callback<BooleanResponse>): Pipeline;
1178
1179 hmget(key: KeyType, ...fields: string[]): Pipeline;
1180
1181 hincrby(key: KeyType, field: string, increment: number, callback?: Callback<number>): Pipeline;
1182
1183 hincrbyfloat(key: KeyType, field: string, increment: number, callback?: Callback<number>): Pipeline;
1184
1185 hdel(key: KeyType, ...fields: string[]): Pipeline;
1186
1187 hlen(key: KeyType, callback?: Callback<number>): Pipeline;
1188
1189 hkeys(key: KeyType, callback?: Callback<string[]>): Pipeline;
1190
1191 hvals(key: KeyType, callback?: Callback<string[]>): Pipeline;
1192
1193 hgetall(key: KeyType, callback?: Callback<Record<string, string>>): Pipeline;
1194
1195 hexists(key: KeyType, field: string, callback?: Callback<BooleanResponse>): Pipeline;
1196
1197 incrby(key: KeyType, increment: number, callback?: Callback<number>): Pipeline;
1198
1199 incrbyfloat(key: KeyType, increment: number, callback?: Callback<number>): Pipeline;
1200
1201 decrby(key: KeyType, decrement: number, callback?: Callback<number>): Pipeline;
1202
1203 getset(key: KeyType, value: ValueType, callback?: Callback<string>): Pipeline;
1204
1205 mset(...args: ValueType[]): Pipeline;
1206 mset(data: object | Map<string, any>, callback?: Callback<string>): Pipeline;
1207
1208 msetnx(...args: ValueType[]): Pipeline;
1209 msetnx(data: object | Map<string, any>, callback?: Callback<BooleanResponse>): Pipeline;
1210
1211 randomkey(callback?: Callback<string>): Pipeline;
1212
1213 select(index: number, callback?: Callback<string>): Pipeline;
1214
1215 move(key: KeyType, db: string, callback?: Callback<BooleanResponse>): Pipeline;
1216
1217 rename(key: KeyType, newkey: KeyType, callback?: Callback<string>): Pipeline;
1218
1219 renamenx(key: KeyType, newkey: KeyType, callback?: Callback<BooleanResponse>): Pipeline;
1220
1221 expire(key: KeyType, seconds: number, callback?: Callback<BooleanResponse>): Pipeline;
1222
1223 pexpire(key: KeyType, milliseconds: number, callback?: Callback<BooleanResponse>): Pipeline;
1224
1225 expireat(key: KeyType, timestamp: number, callback?: Callback<BooleanResponse>): Pipeline;
1226
1227 pexpireat(key: KeyType, millisecondsTimestamp: number, callback?: Callback<BooleanResponse>): Pipeline;
1228
1229 keys(pattern: string, callback?: Callback<string[]>): Pipeline;
1230
1231 dbsize(callback?: Callback<number>): Pipeline;
1232
1233 auth(password: string, callback?: Callback<string>): Pipeline;
1234
1235 ping(callback?: Callback<string>): Pipeline;
1236 ping(message: string, callback?: Callback<string>): Pipeline;
1237
1238 echo(message: string, callback?: Callback<string>): Pipeline;
1239
1240 save(callback?: Callback<string>): Pipeline;
1241
1242 bgsave(callback?: Callback<string>): Pipeline;
1243
1244 bgrewriteaof(callback?: Callback<string>): Pipeline;
1245
1246 shutdown(save: 'SAVE' | 'NOSAVE', callback?: Callback<never>): Pipeline;
1247
1248 lastsave(callback?: Callback<number>): Pipeline;
1249
1250 type(key: KeyType, callback?: Callback<string>): Pipeline;
1251
1252 multi(callback?: Callback<string>): Pipeline;
1253
1254 exec(callback?: Callback<Array<[Error | null, any]>>): Promise<Array<[Error | null, any]>>;
1255
1256 discard(callback?: Callback<any>): Pipeline;
1257
1258 sync(callback?: Callback<any>): Pipeline;
1259
1260 flushdb(callback?: Callback<string>): Pipeline;
1261
1262 flushall(callback?: Callback<string>): Pipeline;
1263
1264 sort(key: KeyType, ...args: string[]): Pipeline;
1265
1266 info(callback?: Callback<string>): Pipeline;
1267 info(section: string, callback?: Callback<string>): Pipeline;
1268
1269 time(callback?: Callback<[string, string]>): Pipeline;
1270
1271 monitor(callback?: Callback<EventEmitter>): Pipeline;
1272
1273 ttl(key: KeyType, callback?: Callback<number>): Pipeline;
1274
1275 pttl(key: KeyType, callback?: Callback<number>): Pipeline;
1276
1277 persist(key: KeyType, callback?: Callback<BooleanResponse>): Pipeline;
1278
1279 slaveof(host: string, port: number, callback?: Callback<string>): Pipeline;
1280
1281 debug(...args: ValueType[]): Pipeline;
1282
1283 config(...args: ValueType[]): Pipeline;
1284
1285 subscribe(...channels: ValueType[]): Pipeline;
1286
1287 unsubscribe(...channels: string[]): Pipeline;
1288
1289 psubscribe(...patterns: string[]): Pipeline;
1290
1291 punsubscribe(...patterns: string[]): Pipeline;
1292
1293 publish(channel: string, message: string, callback?: Callback<number>): Pipeline;
1294
1295 watch(...keys: KeyType[]): Pipeline;
1296
1297 unwatch(callback?: Callback<string>): Pipeline;
1298
1299 cluster(...args: ValueType[]): Pipeline;
1300
1301 restore(...args: ValueType[]): Pipeline;
1302
1303 migrate(...args: ValueType[]): Pipeline;
1304
1305 dump(key: KeyType, callback?: Callback<string>): Pipeline;
1306
1307 object(subcommand: string, ...args: ValueType[]): Pipeline;
1308
1309 client(...args: ValueType[]): Pipeline;
1310
1311 eval(script: string, numKeys: number, ...args: ValueType[]): Pipeline;
1312
1313 evalsha(scriptSha: string, numKeys: string, ...args: ValueType[]): Pipeline;
1314
1315 script(...args: ValueType[]): Pipeline;
1316
1317 quit(callback?: Callback<string>): Pipeline;
1318
1319 scan(cursor: number | string): Pipeline;
1320
1321 scan(cursor: number | string, matchOption: 'match' | 'MATCH', pattern: string): Pipeline;
1322 scan(cursor: number | string, countOption: 'count' | 'COUNT', count: number): Pipeline;
1323
1324 scan(
1325 cursor: number | string,
1326 matchOption: 'match' | 'MATCH',
1327 pattern: string,
1328 countOption: 'count' | 'COUNT',
1329 count: number,
1330 ): Pipeline;
1331 scan(
1332 cursor: number | string,
1333 countOption: 'count' | 'COUNT',
1334 count: number,
1335 matchOption: 'match' | 'MATCH',
1336 pattern: string,
1337 ): Pipeline;
1338 sscan(key: KeyType, cursor: number, ...args: ValueType[]): Pipeline;
1339
1340 hscan(key: KeyType, cursor: number, ...args: ValueType[]): Pipeline;
1341
1342 zscan(key: KeyType, cursor: number, ...args: ValueType[]): Pipeline;
1343
1344 pfmerge(destkey: KeyType, ...sourcekeys: KeyType[]): Pipeline;
1345
1346 pfadd(key: KeyType, ...elements: string[]): Pipeline;
1347
1348 pfcount(...keys: KeyType[]): Pipeline;
1349
1350 xack(key: KeyType, group: string, ...ids: string[]): Pipeline;
1351
1352 xadd(key: KeyType, id: string, ...args: string[]): Pipeline;
1353
1354 xclaim(
1355 key: KeyType,
1356 group: string,
1357 consumer: string,
1358 minIdleTime: number,
1359 id: string,
1360 ...args: ValueType[]
1361 ): Pipeline;
1362
1363 xdel(key: KeyType, ...ids: string[]): Pipeline;
1364
1365 xgroup(...args: ValueType[]): Pipeline;
1366
1367 xinfo(...args: ValueType[]): Pipeline;
1368
1369 xlen(key: KeyType): Pipeline;
1370
1371 xpending(key: KeyType, group: string, ...args: ValueType[]): Pipeline;
1372
1373 xrange(key: KeyType, start: string, end: string, ...args: ValueType[]): Pipeline;
1374
1375 xread(...args: ValueType[]): Pipeline;
1376
1377 xreadgroup(command: 'GROUP' | 'group', group: string, consumer: string, ...args: ValueType[]): Pipeline;
1378
1379 xrevrange(key: KeyType, end: string, start: string, ...args: ValueType[]): Pipeline;
1380
1381 xtrim(key: KeyType, strategy: 'MAXLEN' | 'maxlen', ...args: ValueType[]): Pipeline;
1382 }
1383
1384 interface NodeConfiguration {
1385 host?: string;
1386 port?: number;
1387 }
1388
1389 type ClusterNode = string | number | NodeConfiguration;
1390
1391 type NodeRole = 'master' | 'slave' | 'all';
1392
1393 type CallbackFunction<T = any> = (err?: NodeJS.ErrnoException | null, result?: T) => void;
1394
1395 type Ok = 'OK';
1396
1397 interface Cluster extends EventEmitter, Commander, Commands {
1398 connect(): Promise<void>;
1399 disconnect(): void;
1400 nodes(role?: NodeRole): Redis[];
1401 }
1402
1403 interface ClusterStatic extends EventEmitter {
1404 new (nodes: ClusterNode[], options?: ClusterOptions): Cluster;
1405 }
1406
1407 interface RedisOptions {
1408 port?: number;
1409 host?: string;
1410 /**
1411 * 4 (IPv4) or 6 (IPv6), Defaults to 4.
1412 */
1413 family?: number;
1414 /**
1415 * Local domain socket path. If set the port, host and family will be ignored.
1416 */
1417 path?: string;
1418 /**
1419 * TCP KeepAlive on the socket with a X ms delay before start. Set to a non-number value to disable keepAlive.
1420 */
1421 keepAlive?: number;
1422 connectionName?: string;
1423 /**
1424 * If set, client will send AUTH command with the value of this option when connected.
1425 */
1426 password?: string;
1427 /**
1428 * Database index to use.
1429 */
1430 db?: number;
1431 /**
1432 * When a connection is established to the Redis server, the server might still be loading
1433 * the database from disk. While loading, the server not respond to any commands.
1434 * To work around this, when this option is true, ioredis will check the status of the Redis server,
1435 * and when the Redis server is able to process commands, a ready event will be emitted.
1436 */
1437 enableReadyCheck?: boolean;
1438 keyPrefix?: string;
1439 /**
1440 * When the return value isn't a number, ioredis will stop trying to reconnect.
1441 * Fixed in: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/15858
1442 */
1443 retryStrategy?(times: number): number | void | null;
1444 /**
1445 * By default, all pending commands will be flushed with an error every
1446 * 20 retry attempts. That makes sure commands won't wait forever when
1447 * the connection is down. You can change this behavior by setting
1448 * `maxRetriesPerRequest`.
1449 *
1450 * Set maxRetriesPerRequest to `null` to disable this behavior, and
1451 * every command will wait forever until the connection is alive again
1452 * (which is the default behavior before ioredis v4).
1453 */
1454 maxRetriesPerRequest?: number | null;
1455 /**
1456 * 1/true means reconnect, 2 means reconnect and resend failed command. Returning false will ignore
1457 * the error and do nothing.
1458 */
1459 reconnectOnError?(error: Error): boolean | 1 | 2;
1460 /**
1461 * By default, if there is no active connection to the Redis server, commands are added to a queue
1462 * and are executed once the connection is "ready" (when enableReadyCheck is true, "ready" means
1463 * the Redis server has loaded the database from disk, otherwise means the connection to the Redis
1464 * server has been established). If this option is false, when execute the command when the connection
1465 * isn't ready, an error will be returned.
1466 */
1467 enableOfflineQueue?: boolean;
1468 /**
1469 * The milliseconds before a timeout occurs during the initial connection to the Redis server.
1470 * default: 10000.
1471 */
1472 connectTimeout?: number;
1473 /**
1474 * After reconnected, if the previous connection was in the subscriber mode, client will auto re-subscribe these channels.
1475 * default: true.
1476 */
1477 autoResubscribe?: boolean;
1478 /**
1479 * If true, client will resend unfulfilled commands(e.g. block commands) in the previous connection when reconnected.
1480 * default: true.
1481 */
1482 autoResendUnfulfilledCommands?: boolean;
1483 lazyConnect?: boolean;
1484 tls?: ConnectionOptions;
1485 /**
1486 * default: "master".
1487 */
1488 role?: 'master' | 'slave';
1489 /**
1490 * default: null.
1491 */
1492 name?: string;
1493 sentinelPassword?: string;
1494 sentinels?: Array<{ host: string; port: number }>;
1495 /**
1496 * If `sentinelRetryStrategy` returns a valid delay time, ioredis will try to reconnect from scratch.
1497 * default: function(times) { return Math.min(times * 10, 1000); }
1498 */
1499 sentinelRetryStrategy?(times: number): number | void | null;
1500 /**
1501 * Can be used to prefer a particular slave or set of slaves based on priority.
1502 */
1503 preferredSlaves?: PreferredSlaves;
1504 /**
1505 * Whether to support the `tls` option when connecting to Redis via sentinel mode.
1506 * default: false.
1507 */
1508 enableTLSForSentinelMode?: boolean;
1509 sentinelTLS?: SecureContextOptions;
1510 /**
1511 * NAT map for sentinel connector.
1512 * default: null.
1513 */
1514 natMap?: NatMap;
1515 /**
1516 * Update the given `sentinels` list with new IP addresses when communicating with existing sentinels.
1517 * default: true.
1518 */
1519 updateSentinels?: boolean;
1520 /**
1521 * Enable READONLY mode for the connection. Only available for cluster mode.
1522 * default: false.
1523 */
1524 readOnly?: boolean;
1525 /**
1526 * If you are using the hiredis parser, it's highly recommended to enable this option.
1527 * Create another instance with dropBufferSupport disabled for other commands that you want to return binary instead of string
1528 */
1529 dropBufferSupport?: boolean;
1530 /**
1531 * Whether to show a friendly error stack. Will decrease the performance significantly.
1532 */
1533 showFriendlyErrorStack?: boolean;
1534 }
1535
1536 interface AddressFromResponse {
1537 port: string;
1538 ip: string;
1539 flags?: string;
1540 }
1541
1542 type PreferredSlaves =
1543 | ((slaves: AddressFromResponse[]) => AddressFromResponse | null)
1544 | Array<{ port: string; ip: string; prio?: number }>
1545 | { port: string; ip: string; prio?: number };
1546
1547 type SecureVersion = 'TLSv1.3' | 'TLSv1.2' | 'TLSv1.1' | 'TLSv1';
1548
1549 interface SecureContextOptions {
1550 pfx?: string | Buffer | Array<string | Buffer | object>;
1551 key?: string | Buffer | Array<Buffer | object>;
1552 passphrase?: string;
1553 cert?: string | Buffer | Array<string | Buffer>;
1554 ca?: string | Buffer | Array<string | Buffer>;
1555 ciphers?: string;
1556 honorCipherOrder?: boolean;
1557 ecdhCurve?: string;
1558 clientCertEngine?: string;
1559 crl?: string | Buffer | Array<string | Buffer>;
1560 dhparam?: string | Buffer;
1561 secureOptions?: number; // Value is a numeric bitmask of the `SSL_OP_*` options
1562 secureProtocol?: string; // SSL Method, e.g. SSLv23_method
1563 sessionIdContext?: string;
1564 /**
1565 * Optionally set the maximum TLS version to allow. One
1566 * of `'TLSv1.3'`, `'TLSv1.2'`, `'TLSv1.1'`, or `'TLSv1'`. Cannot be specified along with the
1567 * `secureProtocol` option, use one or the other.
1568 * **Default:** `'TLSv1.3'`, unless changed using CLI options. Using
1569 * `--tls-max-v1.2` sets the default to `'TLSv1.2'`. Using `--tls-max-v1.3` sets the default to
1570 * `'TLSv1.3'`. If multiple of the options are provided, the highest maximum is used.
1571 */
1572 maxVersion?: SecureVersion;
1573 /**
1574 * Optionally set the minimum TLS version to allow. One
1575 * of `'TLSv1.3'`, `'TLSv1.2'`, `'TLSv1.1'`, or `'TLSv1'`. Cannot be specified along with the
1576 * `secureProtocol` option, use one or the other. It is not recommended to use
1577 * less than TLSv1.2, but it may be required for interoperability.
1578 * **Default:** `'TLSv1.2'`, unless changed using CLI options. Using
1579 * `--tls-v1.0` sets the default to `'TLSv1'`. Using `--tls-v1.1` sets the default to
1580 * `'TLSv1.1'`. Using `--tls-min-v1.3` sets the default to
1581 * 'TLSv1.3'. If multiple of the options are provided, the lowest minimum is used.
1582 */
1583 minVersion?: SecureVersion;
1584 }
1585
1586 interface ScanStreamOption {
1587 match?: string;
1588 count?: number;
1589 }
1590
1591 type DNSLookupFunction = (
1592 hostname: string,
1593 callback: (err: NodeJS.ErrnoException | null, address: string, family: number) => void,
1594 ) => void;
1595 interface NatMap {
1596 [key: string]: { host: string; port: number };
1597 }
1598
1599 interface ClusterOptions {
1600 clusterRetryStrategy?(times: number, reason?: Error): number | null;
1601 enableOfflineQueue?: boolean;
1602 enableReadyCheck?: boolean;
1603 scaleReads?: string;
1604 maxRedirections?: number;
1605 retryDelayOnFailover?: number;
1606 retryDelayOnClusterDown?: number;
1607 retryDelayOnTryAgain?: number;
1608 slotsRefreshTimeout?: number;
1609 slotsRefreshInterval?: number;
1610 redisOptions?: RedisOptions;
1611 lazyConnect?: boolean;
1612 dnsLookup?: DNSLookupFunction;
1613 natMap?: NatMap;
1614 }
1615
1616 interface MultiOptions {
1617 pipeline: boolean;
1618 }
1619}