/
template.ts
76 lines (69 loc) 路 2.2 KB
/
template.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { Callback } from "../types";
export type RedisKey = string | Buffer;
export type RedisValue = string | Buffer | number;
// Inspired by https://github.com/mmkal/handy-redis/blob/main/src/generated/interface.ts.
// Should be fixed with https://github.com/Microsoft/TypeScript/issues/1213
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export interface ResultTypes<Result, Context> {
default: Promise<Result>;
pipeline: ChainableCommander;
}
export interface ChainableCommander
extends RedisCommander<{ type: "pipeline" }> {}
export type ClientContext = { type: keyof ResultTypes<unknown, unknown> };
export type Result<T, Context extends ClientContext> =
// prettier-break
ResultTypes<T, Context>[Context["type"]];
interface RedisCommander<Context extends ClientContext = { type: "default" }> {
/**
* Call arbitrary commands.
*
* `redis.call('set', 'foo', 'bar')` is the same as `redis.set('foo', 'bar')`,
* so the only case you need to use this method is when the command is not
* supported by ioredis.
*
* ```ts
* redis.call('set', 'foo', 'bar');
* redis.call('get', 'foo', (err, value) => {
* // value === 'bar'
* });
* ```
*/
call(command: string, callback?: Callback<unknown>): Result<unknown, Context>;
call(
command: string,
args: (string | Buffer | number)[],
callback?: Callback<unknown>
): Result<unknown, Context>;
call(
...args: [
command: string,
...args: (string | Buffer | number)[],
callback: Callback<unknown>
]
): Result<unknown, Context>;
call(
...args: [command: string, ...args: (string | Buffer | number)[]]
): Result<unknown, Context>;
callBuffer(
command: string,
callback?: Callback<unknown>
): Result<unknown, Context>;
callBuffer(
command: string,
args: (string | Buffer | number)[],
callback?: Callback<unknown>
): Result<unknown, Context>;
callBuffer(
...args: [
command: string,
...args: (string | Buffer | number)[],
callback: Callback<unknown>
]
): Result<unknown, Context>;
callBuffer(
...args: [command: string, ...args: (string | Buffer | number)[]]
): Result<unknown, Context>;
////
}
export default RedisCommander;