fix(mining-service): Redis锁使用毫秒PX代替秒EX支持小数TTL

This commit is contained in:
hailin 2026-01-14 03:52:22 -08:00
parent 901247366d
commit 09b15da3cb
1 changed files with 2 additions and 1 deletions

View File

@ -64,7 +64,8 @@ export class RedisService implements OnModuleInit, OnModuleDestroy {
async acquireLock(lockKey: string, ttlSeconds: number = 30): Promise<string | null> {
const lockValue = `${Date.now()}-${Math.random().toString(36).substring(7)}`;
const result = await this.client.set(lockKey, lockValue, 'EX', ttlSeconds, 'NX');
const ttlMs = Math.round(ttlSeconds * 1000);
const result = await this.client.set(lockKey, lockValue, 'PX', ttlMs, 'NX');
return result === 'OK' ? lockValue : null;
}