UNPKG

@daiso-tech/core

Version:

The library offers flexible, framework-agnostic solutions for modern web applications, built on adaptable components that integrate seamlessly with popular frameworks like Next Js.

44 lines (43 loc) 1.97 kB
/** * @module Lock */ import type { TimeSpan } from "../../../../utilities/_module-exports.js"; import { LOCK_REFRESH_RESULT, type ILockAdapter, type LockRefreshResult } from "../../../../lock/contracts/_module-exports.js"; import type { Redis } from "ioredis"; import type { Result } from "ioredis"; declare module "ioredis" { interface RedisCommander<Context> { daiso_lock_acquire(key: string, owner: string, expiration: string): Result<number, Context>; daiso_lock_release(key: string, owner: string): Result<number, Context>; daiso_lock_refresh(key: string, owner: string, expiration: string, REFRESHED: typeof LOCK_REFRESH_RESULT.REFRESHED, UNOWNED_REFRESH: typeof LOCK_REFRESH_RESULT.UNOWNED_REFRESH, UNEXPIRABLE_KEY: typeof LOCK_REFRESH_RESULT.UNEXPIRABLE_KEY): Result<LockRefreshResult, Context>; } } /** * 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/adapters"` * @group Adapters */ export declare class RedisLockAdapter implements ILockAdapter { private readonly database; /** * @example * ```ts * import { RedisLockAdapter } from "@daiso-tech/core/lock/adapters"; * 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; acquire(key: string, owner: string, ttl: TimeSpan | null): Promise<boolean>; release(key: string, owner: string): Promise<boolean>; forceRelease(key: string): Promise<boolean>; refresh(key: string, owner: string, ttl: TimeSpan): Promise<LockRefreshResult>; }