1
0

multi-command.d.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import COMMANDS from './commands';
  2. import { RedisCommand, RedisCommandArguments, RedisCommandRawReply, RedisFunctions, RedisModules, RedisExtensions, RedisScript, RedisScripts, ExcludeMappedString, RedisFunction } from '../commands';
  3. import { RedisMultiQueuedCommand } from '../multi-command';
  4. type CommandSignature<C extends RedisCommand, M extends RedisModules, F extends RedisFunctions, S extends RedisScripts> = (...args: Parameters<C['transformArguments']>) => RedisClientMultiCommandType<M, F, S>;
  5. type WithCommands<M extends RedisModules, F extends RedisFunctions, S extends RedisScripts> = {
  6. [P in keyof typeof COMMANDS]: CommandSignature<(typeof COMMANDS)[P], M, F, S>;
  7. };
  8. type WithModules<M extends RedisModules, F extends RedisFunctions, S extends RedisScripts> = {
  9. [P in keyof M as ExcludeMappedString<P>]: {
  10. [C in keyof M[P] as ExcludeMappedString<C>]: CommandSignature<M[P][C], M, F, S>;
  11. };
  12. };
  13. type WithFunctions<M extends RedisModules, F extends RedisFunctions, S extends RedisScripts> = {
  14. [P in keyof F as ExcludeMappedString<P>]: {
  15. [FF in keyof F[P] as ExcludeMappedString<FF>]: CommandSignature<F[P][FF], M, F, S>;
  16. };
  17. };
  18. type WithScripts<M extends RedisModules, F extends RedisFunctions, S extends RedisScripts> = {
  19. [P in keyof S as ExcludeMappedString<P>]: CommandSignature<S[P], M, F, S>;
  20. };
  21. export type RedisClientMultiCommandType<M extends RedisModules, F extends RedisFunctions, S extends RedisScripts> = RedisClientMultiCommand & WithCommands<M, F, S> & WithModules<M, F, S> & WithFunctions<M, F, S> & WithScripts<M, F, S>;
  22. type InstantiableRedisMultiCommand<M extends RedisModules, F extends RedisFunctions, S extends RedisScripts> = new (...args: ConstructorParameters<typeof RedisClientMultiCommand>) => RedisClientMultiCommandType<M, F, S>;
  23. export type RedisClientMultiExecutor = (queue: Array<RedisMultiQueuedCommand>, selectedDB?: number, chainId?: symbol) => Promise<Array<RedisCommandRawReply>>;
  24. export default class RedisClientMultiCommand {
  25. #private;
  26. static extend<M extends RedisModules, F extends RedisFunctions, S extends RedisScripts>(extensions?: RedisExtensions<M, F, S>): InstantiableRedisMultiCommand<M, F, S>;
  27. readonly v4: Record<string, any>;
  28. constructor(executor: RedisClientMultiExecutor, legacyMode?: boolean);
  29. commandsExecutor(command: RedisCommand, args: Array<unknown>): this;
  30. SELECT(db: number, transformReply?: RedisCommand['transformReply']): this;
  31. select: (db: number, transformReply?: RedisCommand['transformReply']) => this;
  32. addCommand(args: RedisCommandArguments, transformReply?: RedisCommand['transformReply']): this;
  33. functionsExecutor(fn: RedisFunction, args: Array<unknown>, name: string): this;
  34. scriptsExecutor(script: RedisScript, args: Array<unknown>): this;
  35. exec(execAsPipeline?: boolean): Promise<Array<RedisCommandRawReply>>;
  36. EXEC: (execAsPipeline?: boolean) => Promise<Array<RedisCommandRawReply>>;
  37. execAsPipeline(): Promise<Array<RedisCommandRawReply>>;
  38. }
  39. export {};