UNPKG

node-redisson

Version:

Distributed lock with Redis implementation for Node.js

37 lines (36 loc) 2.17 kB
import { ICommandExecutor, SYMBOL_TIMEOUT, RedissonRedis } from '../contracts/ICommandExecutor'; import { Result, RedisOptions } from 'ioredis'; import { ServiceManager } from '../manager/ServiceManager'; import { IRedissonInnerConfig } from '../contracts/IRedissonConfig'; import { PartialRecord } from '../types'; export type RedisScriptsKey = 'rTryLockInner' | 'rUnlockInner' | 'rRenewExpiration' | 'rForceUnlock'; export type RedisScriptsValue = NonNullable<RedisOptions['scripts']>[string]; export type RedisScripts = Record<RedisScriptsKey, RedisScriptsValue>; declare module 'ioredis' { interface RedisCommander<Context> { rTryLockInner(lockKey: string, leaseTime: bigint, clientName: string): Result<number | null, Context>; rRenewExpiration(lockKey: string, leaseTime: bigint, clientName: string): Result<0 | 1, Context>; rUnlockInner(lockKey: string, channelName: string, unlockLatchName: string, unlockMessage: string, leaseTime: bigint, clientName: string, timeout: number): Result<0 | 1, Context>; rForceUnlock(lockKey: string, channelName: string, unlockMessage: string): Result<0 | 1, Context>; } } export declare const DEFAULT_REDIS_SCRIPTS: RedisScripts; export declare abstract class CommandExecutor implements ICommandExecutor { private readonly config; abstract subscribe<T>(eventName: string, listener: (e: T) => void): Promise<void>; abstract unsubscribe(eventName: string, listener: (...args: any[]) => void): Promise<void>; abstract subscribeOnce<T>(eventName: string, listener: (e: T) => void): Promise<void>; abstract publish(eventName: string, e: string): Promise<string | null>; abstract getRedisScripts<K>(): PartialRecord<RedisScriptsKey, string>; private _id; private _redis; private _subscribeRedis; constructor(config: IRedissonInnerConfig); private createRedis; get id(): string; get redissonConfig(): IRedissonInnerConfig; get serviceManager(): ServiceManager; get redis(): RedissonRedis; get subscribeRedis(): RedissonRedis; waitSubscribeOnce<T>(eventName: string, timeout?: number): Promise<T | typeof SYMBOL_TIMEOUT>; }