forked from xiangwang25/whale-town-end-v2
refactor: harden task authority and room mutations
This commit is contained in:
@@ -134,6 +134,18 @@ export class RealRedisService implements IRedisService, OnModuleDestroy {
|
||||
}
|
||||
}
|
||||
|
||||
async setIfAbsent(key: string, value: string, ttl?: number): Promise<boolean> {
|
||||
try {
|
||||
const result = ttl && ttl > 0
|
||||
? await this.redis.set(key, value, 'EX', ttl, 'NX')
|
||||
: await this.redis.set(key, value, 'NX');
|
||||
return result === 'OK';
|
||||
} catch (error) {
|
||||
this.logger.error(`原子设置Redis键失败: ${key}`, error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取键对应的值
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user