优化synclocker

This commit is contained in:
CounterFire2023 2024-04-24 21:54:36 +08:00
parent 97f8d8f92c
commit d0bfccbff8
2 changed files with 4 additions and 4 deletions

View File

@ -139,7 +139,7 @@ export class ApiServer {
private setFormatSend() {
this.server.addHook('preSerialization', async (req: FastifyRequest, reply: FastifyReply, payload) => {
reply.header('X-Powered-By', 'PHP/5.4.16')
new SyncLocker().unlock(req)
await new SyncLocker().unlock(req)
// @ts-ignore
if (!payload.errcode) {
payload = {

View File

@ -24,7 +24,7 @@ const redlock = new Redlock(
// The max number of times Redlock will attempt to lock a resource
// before erroring.
retryCount: 10,
retryCount: 0,
// the time in ms between attempts
retryDelay: 200, // time in ms
@ -51,9 +51,9 @@ redlock.on('error', error => {
@singleton
export class SyncLocker {
public unlock(req: IRequest) {
public async unlock(req: IRequest) {
if (req.lock) {
req.lock.release()
await req.lock.release()
}
}