You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-10 11:43:01 +03:00
55 lines
1.4 KiB
TypeScript
55 lines
1.4 KiB
TypeScript
import { RedisArgument, ArrayReply, BlobStringReply, Command, NumberReply, Resp2Reply, RespVersions, TuplesToMapReply } from '../RESP/types';
|
|
|
|
export interface HelloOptions {
|
|
AUTH?: {
|
|
username: RedisArgument;
|
|
password: RedisArgument;
|
|
};
|
|
SETNAME?: string;
|
|
}
|
|
|
|
export type HelloReply = TuplesToMapReply<[
|
|
[BlobStringReply<'server'>, BlobStringReply],
|
|
[BlobStringReply<'version'>, BlobStringReply],
|
|
[BlobStringReply<'proto'>, NumberReply<RespVersions>],
|
|
[BlobStringReply<'id'>, NumberReply],
|
|
[BlobStringReply<'mode'>, BlobStringReply],
|
|
[BlobStringReply<'role'>, BlobStringReply],
|
|
[BlobStringReply<'modules'>, ArrayReply<BlobStringReply>]
|
|
]>;
|
|
|
|
export default {
|
|
transformArguments(protoover: RespVersions, options?: HelloOptions) {
|
|
const args: Array<RedisArgument> = ['HELLO', protoover.toString()];
|
|
|
|
if (options?.AUTH) {
|
|
args.push(
|
|
'AUTH',
|
|
options.AUTH.username,
|
|
options.AUTH.password
|
|
);
|
|
}
|
|
|
|
if (options?.SETNAME) {
|
|
args.push(
|
|
'SETNAME',
|
|
options.SETNAME
|
|
);
|
|
}
|
|
|
|
return args;
|
|
},
|
|
transformReply: {
|
|
2: (reply: Resp2Reply<HelloReply>) => ({
|
|
server: reply[1],
|
|
version: reply[3],
|
|
proto: reply[5],
|
|
id: reply[7],
|
|
mode: reply[9],
|
|
role: reply[11],
|
|
modules: reply[13]
|
|
}),
|
|
3: undefined as unknown as () => HelloReply
|
|
}
|
|
} as const satisfies Command;
|