-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathMIGRATE.ts
65 lines (55 loc) · 1.31 KB
/
MIGRATE.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
import { RedisCommandArgument, RedisCommandArguments } from '.';
import { AuthOptions } from './AUTH';
interface MigrateOptions {
COPY?: true;
REPLACE?: true;
AUTH?: AuthOptions;
}
export function transformArguments(
host: RedisCommandArgument,
port: number,
key: RedisCommandArgument | Array<RedisCommandArgument>,
destinationDb: number,
timeout: number,
options?: MigrateOptions
): RedisCommandArguments {
const args = ['MIGRATE', host, port.toString()],
isKeyArray = Array.isArray(key);
if (isKeyArray) {
args.push('');
} else {
args.push(key);
}
args.push(
destinationDb.toString(),
timeout.toString()
);
if (options?.COPY) {
args.push('COPY');
}
if (options?.REPLACE) {
args.push('REPLACE');
}
if (options?.AUTH) {
if (options.AUTH.username) {
args.push(
'AUTH2',
options.AUTH.username,
options.AUTH.password
);
} else {
args.push(
'AUTH',
options.AUTH.password
);
}
}
if (isKeyArray) {
args.push(
'KEYS',
...key
);
}
return args;
}
export declare function transformReply(): string;