/** * @module Lock */ import { type Result, type Redis } from "ioredis"; import { type IReadableContext } from "../../../../execution-context/contracts/_module.js"; import { type ILockAdapter, type ILockAdapterState } from "../../../../lock/contracts/_module.js"; import { type TimeSpan } from "../../../../time-span/implementations/_module.js"; declare module "ioredis" { interface RedisCommander { /** * * @param key * @param lockId * @param expiration As unix timestamp in miliseconds */ daiso_lock_acquire(key: string, lockId: string, expiration: number | null): Result<1 | 0, Context>; daiso_lock_release(key: string, lockId: string): Result<1 | 0, Context>; /** * * @param key * @param lockId * @param expiration As unix timestamp in miliseconds */ daiso_lock_refresh(key: string, lockId: string, expiration: number): Result<1 | 0, Context>; /** * @returns {string} {@link IRedisJsonLockState | `IRedisJsonLockState`} or `null` as json string. */ daiso_lock_get_state(key: string): Result; } } /** * To utilize the `RedisLockAdapter`, you must install the [`"ioredis"`](https://www.npmjs.com/package/ioredis) package. * * Note in order to use `RedisLockAdapter` correctly, ensure you use a single, consistent database across all server instances. * * IMPORT_PATH: `"@daiso-tech/core/lock/redis-lock-adapter"` * @group Adapters */ export declare class RedisLockAdapter implements ILockAdapter { private readonly database; /** * @example * ```ts * import { RedisLockAdapter } from "@daiso-tech/core/lock/redis-lock-adapter"; * import Redis from "ioredis"; * * const database = new Redis("YOUR_REDIS_CONNECTION_STRING"); * const lockAdapter = new RedisLockAdapter(database); * ``` */ constructor(database: Redis); private initAquireCommand; private initReleaseCommand; private initRefreshComand; private initGetStateComand; acquire(key: string, lockId: string, ttl: TimeSpan | null, _context: IReadableContext): Promise; release(key: string, lockId: string, _context: IReadableContext): Promise; forceRelease(key: string, _context: IReadableContext): Promise; refresh(key: string, lockId: string, ttl: TimeSpan, _context: IReadableContext): Promise; getState(key: string, _context: IReadableContext): Promise; }