bullmq 5.77.2 → 5.77.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/classes/bun-redis-client.js +59 -56
- package/dist/cjs/tsconfig-cjs.tsbuildinfo +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/classes/bun-redis-client.js +59 -56
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/package.json +1 -1
|
@@ -85,9 +85,6 @@ class BunRedisAdapter extends events_1.EventEmitter {
|
|
|
85
85
|
this.hasConnected = false;
|
|
86
86
|
this.closed = false;
|
|
87
87
|
this.closing = false;
|
|
88
|
-
// Serialize raw send() calls per connection to avoid Bun delivering
|
|
89
|
-
// concurrent command responses to the wrong pending promise.
|
|
90
|
-
this.sendQueue = Promise.resolve();
|
|
91
88
|
// Auto-reconnect state
|
|
92
89
|
this.reconnecting = false;
|
|
93
90
|
this.reconnectTimer = null;
|
|
@@ -404,31 +401,24 @@ class BunRedisAdapter extends events_1.EventEmitter {
|
|
|
404
401
|
}));
|
|
405
402
|
}
|
|
406
403
|
sendCommand(command, args) {
|
|
407
|
-
// If the connection is already closing/closed, return a rejected promise
|
|
408
|
-
// directly without going through sendQueue.
|
|
404
|
+
// If the connection is already closing/closed, return a rejected promise.
|
|
409
405
|
if (this.closing || this.closed) {
|
|
410
406
|
return Promise.reject(new connection_closed_error_1.ConnectionClosedError('Connection is closed'));
|
|
411
407
|
}
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
408
|
+
// Send directly to the underlying Bun client. Redis protocol guarantees
|
|
409
|
+
// responses arrive in the same order as requests on a single connection,
|
|
410
|
+
// so concurrent send() calls are safe and enable implicit pipelining
|
|
411
|
+
// (multiple commands written to the socket before any response is read).
|
|
412
|
+
// MULTI/EXEC transactions don't go through this path — they are issued
|
|
413
|
+
// as a synchronous burst of raw `send()` calls in
|
|
414
|
+
// `BunRedisTransaction.exec()`, which guarantees the MULTI…EXEC frames
|
|
415
|
+
// are written contiguously without any other command interleaving.
|
|
416
|
+
return this.raw.send(command, args).catch((err) => {
|
|
417
|
+
if (isBunConnectionClosedError(err)) {
|
|
418
|
+
return Promise.reject(new connection_closed_error_1.ConnectionClosedError(this.closing || this.closed ? 'Connection is closed' : err.message, err));
|
|
415
419
|
}
|
|
416
|
-
|
|
417
|
-
if (isBunConnectionClosedError(err)) {
|
|
418
|
-
return Promise.reject(new connection_closed_error_1.ConnectionClosedError(this.closing || this.closed
|
|
419
|
-
? 'Connection is closed'
|
|
420
|
-
: err.message, err));
|
|
421
|
-
}
|
|
422
|
-
throw err;
|
|
423
|
-
});
|
|
420
|
+
throw err;
|
|
424
421
|
});
|
|
425
|
-
this.sendQueue = run.then(() => undefined, () => undefined);
|
|
426
|
-
return run;
|
|
427
|
-
}
|
|
428
|
-
async queueExclusive(operation) {
|
|
429
|
-
const run = this.sendQueue.then(operation, operation);
|
|
430
|
-
this.sendQueue = run.then(() => undefined, () => undefined);
|
|
431
|
-
return run;
|
|
432
422
|
}
|
|
433
423
|
// ---------------------------------------------------------------
|
|
434
424
|
// Pipeline / Transaction
|
|
@@ -973,41 +963,54 @@ class BunRedisTransaction {
|
|
|
973
963
|
return [null, value];
|
|
974
964
|
});
|
|
975
965
|
}
|
|
976
|
-
// Execute as
|
|
977
|
-
//
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
});
|
|
966
|
+
// Execute as a pipelined MULTI/EXEC block. Redis supports multiple
|
|
967
|
+
// MULTI/EXEC blocks pipelined on the same connection — each MULTI starts
|
|
968
|
+
// a new transaction context and EXEC commits it, responses arrive in
|
|
969
|
+
// order. We fire MULTI + all commands + EXEC synchronously (no await
|
|
970
|
+
// between them) so they're written to the socket buffer as one contiguous
|
|
971
|
+
// burst with no opportunity for interleaving from other async contexts.
|
|
972
|
+
//
|
|
973
|
+
// The MULTI and per-command `send()` calls are intentionally fire-and-
|
|
974
|
+
// forget for performance, but their returned promises must still have a
|
|
975
|
+
// rejection handler attached to avoid Bun emitting "unhandled promise
|
|
976
|
+
// rejection" warnings if the connection drops or Redis returns an error
|
|
977
|
+
// reply before we reach EXEC. The actual failure is reported through the
|
|
978
|
+
// awaited EXEC promise (which Redis rejects in the same situations), or
|
|
979
|
+
// bubbles up via the surrounding `try/catch`.
|
|
980
|
+
const swallow = (_) => {
|
|
981
|
+
/* error surfaces via EXEC or the outer try/catch */
|
|
982
|
+
};
|
|
983
|
+
try {
|
|
984
|
+
// Fire MULTI without awaiting — no round-trip needed before commands.
|
|
985
|
+
this.raw.send('MULTI', []).catch(swallow);
|
|
986
|
+
// Fire all queued commands synchronously (no awaits).
|
|
987
|
+
for (const { cmd, args } of this.commands) {
|
|
988
|
+
this.raw.send(cmd, args).catch(swallow);
|
|
1000
989
|
}
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
990
|
+
// EXEC is the only await — it returns the array of results.
|
|
991
|
+
const results = await this.raw.send('EXEC', []);
|
|
992
|
+
if (!results) {
|
|
993
|
+
return null;
|
|
994
|
+
}
|
|
995
|
+
// Normalize to ioredis format: [Error | null, value][]
|
|
996
|
+
return results.map((result, i) => {
|
|
997
|
+
if (result instanceof Error) {
|
|
998
|
+
return [result, null];
|
|
1008
999
|
}
|
|
1009
|
-
|
|
1000
|
+
const transformer = this.transformers[i];
|
|
1001
|
+
const value = transformer ? transformer(result) : result;
|
|
1002
|
+
return [null, value];
|
|
1003
|
+
});
|
|
1004
|
+
}
|
|
1005
|
+
catch (err) {
|
|
1006
|
+
// Try to discard the MULTI state on error
|
|
1007
|
+
try {
|
|
1008
|
+
await this.raw.send('DISCARD', []);
|
|
1010
1009
|
}
|
|
1011
|
-
|
|
1010
|
+
catch (_a) {
|
|
1011
|
+
// ignore
|
|
1012
|
+
}
|
|
1013
|
+
throw err;
|
|
1014
|
+
}
|
|
1012
1015
|
}
|
|
1013
1016
|
}
|