@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.68 kB
TypeScript
/**
* @module Lock
*/
import type { TimeSpan } from "../../../../utilities/_module-exports.js";
import type { ILockAdapter } 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, ttl: string): Result<number, Context>;
daiso_lock_release(key: string, owner: string): Result<number, Context>;
daiso_lock_refresh(key: string, owner: string, ttl: string): Result<number, Context>;
}
}
/**
* To utilize the `RedisLockAdapter`, you must install the `"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<void>;
refresh(key: string, owner: string, ttl: TimeSpan): Promise<boolean>;
}