1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-07 13:22:56 +03:00
This commit is contained in:
Leibale
2023-06-20 20:04:05 -04:00
parent f22879dffa
commit 4894c26458
35 changed files with 848 additions and 662 deletions

View File

@@ -1,83 +1,86 @@
// import { RedisCommandArgument, RedisCommandArguments } from '.';
import { RedisArgument, SimpleStringReply, Command } from '../RESP/types';
import { RedisVariadicArgument } from './generic-transformers';
interface CommonOptions {
REDIRECT?: number;
NOLOOP?: boolean;
}
// interface CommonOptions {
// REDIRECT?: number;
// NOLOOP?: boolean;
// }
interface BroadcastOptions {
BCAST?: boolean;
PREFIX?: RedisVariadicArgument;
}
// interface BroadcastOptions {
// BCAST?: boolean;
// PREFIX?: RedisCommandArgument | Array<RedisCommandArgument>;
// }
interface OptInOptions {
OPTIN?: boolean;
}
// interface OptInOptions {
// OPTIN?: boolean;
// }
interface OptOutOptions {
OPTOUT?: boolean;
}
// interface OptOutOptions {
// OPTOUT?: boolean;
// }
type ClientTrackingOptions = CommonOptions & (
BroadcastOptions |
OptInOptions |
OptOutOptions
);
// type ClientTrackingOptions = CommonOptions & (
// BroadcastOptions |
// OptInOptions |
// OptOutOptions
// );
export default {
FIRST_KEY_INDEX: undefined,
IS_READ_ONLY: true,
transformArguments<M extends boolean>(
mode: M,
options?: M extends true ? ClientTrackingOptions : never
) {
const args: Array<RedisArgument> = [
'CLIENT',
'TRACKING',
mode ? 'ON' : 'OFF'
];
// export function transformArguments<M extends boolean>(
// mode: M,
// options?: M extends true ? ClientTrackingOptions : undefined
// ): RedisCommandArguments {
// const args: RedisCommandArguments = [
// 'CLIENT',
// 'TRACKING',
// mode ? 'ON' : 'OFF'
// ];
if (mode) {
if (options?.REDIRECT) {
args.push(
'REDIRECT',
options.REDIRECT.toString()
);
}
// if (mode) {
// if (options?.REDIRECT) {
// args.push(
// 'REDIRECT',
// options.REDIRECT.toString()
// );
// }
if (isBroadcast(options)) {
args.push('BCAST');
// if (isBroadcast(options)) {
// args.push('BCAST');
if (options?.PREFIX) {
if (Array.isArray(options.PREFIX)) {
for (const prefix of options.PREFIX) {
args.push('PREFIX', prefix);
}
} else {
args.push('PREFIX', options.PREFIX);
}
}
} else if (isOptIn(options)) {
args.push('OPTIN');
} else if (isOptOut(options)) {
args.push('OPTOUT');
}
// if (options?.PREFIX) {
// if (Array.isArray(options.PREFIX)) {
// for (const prefix of options.PREFIX) {
// args.push('PREFIX', prefix);
// }
// } else {
// args.push('PREFIX', options.PREFIX);
// }
// }
// } else if (isOptIn(options)) {
// args.push('OPTIN');
// } else if (isOptOut(options)) {
// args.push('OPTOUT');
// }
if (options?.NOLOOP) {
args.push('NOLOOP');
}
}
// if (options?.NOLOOP) {
// args.push('NOLOOP');
// }
// }
return args;
},
transformReply: undefined as unknown as () => SimpleStringReply<'OK'>
} as const satisfies Command;
// return args;
// }
function isBroadcast(options?: ClientTrackingOptions): options is BroadcastOptions {
return (options as BroadcastOptions)?.BCAST === true;
}
// function isBroadcast(options?: ClientTrackingOptions): options is BroadcastOptions {
// return (options as BroadcastOptions)?.BCAST === true;
// }
function isOptIn(options?: ClientTrackingOptions): options is OptInOptions {
return (options as OptInOptions)?.OPTIN === true;
}
// function isOptIn(options?: ClientTrackingOptions): options is OptInOptions {
// return (options as OptInOptions)?.OPTIN === true;
// }
// function isOptOut(options?: ClientTrackingOptions): options is OptOutOptions {
// return (options as OptOutOptions)?.OPTOUT === true;
// }
// export declare function transformReply(): 'OK' | Buffer;
function isOptOut(options?: ClientTrackingOptions): options is OptOutOptions {
return (options as OptOutOptions)?.OPTOUT === true;
}