nstarter-lock
Version:
Mutex/Semaphore for Project NStarter.
77 lines (67 loc) • 1.84 kB
text/typescript
/**
* Copyright (c) 2015-2023, FineX, All Rights Reserved.
* @author vista@fanruan.com
* @date 2022/10/15
*/
import { getRedis } from './redis';
/**
* 帮助类:处理锁和信号量的持有者信息
*/
export class LockerInfoHelper {
readonly
readonly
readonly
/**
* 构造函数
* @param resourceKey - 资源键名
* @param locker - 持有者信息
*/
constructor(resourceKey: string, locker?: string) {
this.
this.
this.
}
/**
* 获取资源键名
*/
public get resourceKey(): string {
return this.
}
/**
* 获取持有者信息键名
*/
public get lockerInfoKey(): string {
return this.
}
/**
* 获取持有者信息
*/
public get locker(): string | undefined {
return this.
}
/**
* 设置持有者信息
* @param value - 持有者信息值
*/
public async setLockerInfo(value: string): Promise<void> {
const provider = getRedis();
// 24 小时过期
const ttl = 24 * 60 * 60;
await provider.client.set(this.
}
/**
* 获取持有者信息
* @returns 持有者信息,如果不存在则返回null
*/
public async getLockerInfo(): Promise<string | null> {
const provider = getRedis();
return provider.client.get(this.
}
/**
* 删除持有者信息
*/
public async deleteLockerInfo(): Promise<void> {
const provider = getRedis();
await provider.client.del(this.
}
}