fix(mining-service): Redis锁使用毫秒PX代替秒EX支持小数TTL
This commit is contained in:
parent
901247366d
commit
09b15da3cb
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue