1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-09 00:22:08 +03:00
Files
node-redis/lib/commands/MIGRATE.ts
Leibale Eidelman 77664c31ff Release 4.0.0-rc.1 (#1648)
* update workflows & README

* add .deepsource.toml

* fix client.quit, add error events on cluster, fix some "deepsource.io" warnings

* Release 4.0.0-rc.1
2021-09-06 16:02:53 -04:00

66 lines
1.3 KiB
TypeScript

import { AuthOptions } from './AUTH';
import { transformReplyString } from './generic-transformers';
interface MigrateOptions {
COPY?: true;
REPLACE?: true;
AUTH?: AuthOptions;
}
export function transformArguments(
host: string,
port: number,
key: string | Array<string>,
destinationDb: number,
timeout: number,
options?: MigrateOptions
): Array<string> {
const args = ['MIGRATE', host, port.toString()],
isKeyString = typeof key === 'string';
if (isKeyString) {
args.push(key);
} else {
args.push('""');
}
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 (!isKeyString) {
args.push(
'KEYS',
...key
);
}
return args;
}
export const transformReply = transformReplyString;