@imqueue/core 3.3.2 → 3.3.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/AGENTS.md +6 -0
- package/CHANGELOG.md +18 -0
- package/README.md +6 -0
- package/package.json +1 -1
- package/src/RedisQueue.d.ts +32 -0
- package/src/RedisQueue.js +80 -8
- package/.claude/settings.local.json +0 -9
package/AGENTS.md
CHANGED
|
@@ -78,6 +78,12 @@ timeout is 15s per test. Run a single spec after a build with
|
|
|
78
78
|
notification events. If Redis has the `CONFIG` command disabled (e.g. AWS
|
|
79
79
|
ElastiCache), keyspace notifications must be enabled out of band:
|
|
80
80
|
`notify-keyspace-events Ex`.
|
|
81
|
+
- **Keyspace-notification flags are merged, never overwritten.**
|
|
82
|
+
`notify-keyspace-events` is server-global, so `watch()` reads the current
|
|
83
|
+
value and appends only the missing `E`/`x` flags (`A` counts as covering
|
|
84
|
+
`x`), skipping `CONFIG SET` when the config already suffices. Do not go back
|
|
85
|
+
to setting a literal — that silently breaks other consumers of the same
|
|
86
|
+
Redis.
|
|
81
87
|
- **Messages must be JSON-serializable** (`IJson`/`JsonObject`). Delayed
|
|
82
88
|
delivery is supported via the send `delay` argument.
|
|
83
89
|
- Scaling the number of workers must **not** increase Redis traffic — preserve
|
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,24 @@ behavior changes needed a written record; earlier history is in the git log.
|
|
|
5
5
|
|
|
6
6
|
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [3.3.3] - 2026-08-18
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- **Starting a queue overwrote the redis keyspace-notification configuration.**
|
|
13
|
+
`notify-keyspace-events` is a server-global setting, and the watcher owner set
|
|
14
|
+
it to the literal `Ex` on every connection establishment. Any other flag —
|
|
15
|
+
enabled by an operator through a config file or by other code sharing the same
|
|
16
|
+
redis — was silently dropped, breaking every consumer that relied on it, and
|
|
17
|
+
coming back after each reconnect.
|
|
18
|
+
|
|
19
|
+
The current value is now read first, only the missing `E`/`x` flags are
|
|
20
|
+
appended, and `CONFIG SET` is skipped entirely when the configuration already
|
|
21
|
+
suffices. `A` is recognised as covering `x`, so a server on `AK` only gains
|
|
22
|
+
`E`. When `CONFIG` is unavailable (e.g. AWS ElastiCache) the read fails and
|
|
23
|
+
the configuration is left untouched — enable `notify-keyspace-events` out of
|
|
24
|
+
band there, as before.
|
|
25
|
+
|
|
8
26
|
## [3.2.4] - 2026-07-26
|
|
9
27
|
|
|
10
28
|
### Fixed
|
package/README.md
CHANGED
|
@@ -59,6 +59,12 @@ notification events (particularly when using AWS ElasticCache), like this:
|
|
|
59
59
|
notify-keyspace-events Ex
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
+
Otherwise the queue configures them itself, and does so without disturbing your
|
|
63
|
+
own setup: it reads `notify-keyspace-events`, appends only the flags it is
|
|
64
|
+
missing (`E` and `x`) and leaves everything else — including flags enabled by
|
|
65
|
+
an operator or by other code sharing the same Redis — in place. Any superset of
|
|
66
|
+
`Ex` is accepted as is, so no `CONFIG SET` is issued at all.
|
|
67
|
+
|
|
62
68
|
More adapters will be added in the future as needed.
|
|
63
69
|
|
|
64
70
|
# Install
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@imqueue/core",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.3",
|
|
4
4
|
"description": "Fast JSON message queue over Redis for inter-service communication in Node.js & TypeScript microservices — the transport layer of the @imqueue framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"message-queue",
|
package/src/RedisQueue.d.ts
CHANGED
|
@@ -628,6 +628,38 @@ export declare class RedisQueue extends EventEmitter<EventMap> implements IMessa
|
|
|
628
628
|
* Clears safe check interval
|
|
629
629
|
*/
|
|
630
630
|
private cleanSafeCheckInterval;
|
|
631
|
+
/**
|
|
632
|
+
* Reads the keyspace-notification flags currently configured on the
|
|
633
|
+
* server.
|
|
634
|
+
*
|
|
635
|
+
* @returns the raw flags string, or an empty string when notifications
|
|
636
|
+
* are disabled
|
|
637
|
+
*
|
|
638
|
+
* @remarks
|
|
639
|
+
* `CONFIG GET` replies as a flat `[name, value]` array over RESP2 and as a
|
|
640
|
+
* map over RESP3, so both shapes are accepted.
|
|
641
|
+
*/
|
|
642
|
+
private currentKeyspaceEvents;
|
|
643
|
+
/**
|
|
644
|
+
* Returns the flags from {@link NOTIFY_EVENTS_REQUIRED} that the given
|
|
645
|
+
* configuration does not already provide.
|
|
646
|
+
*
|
|
647
|
+
* @param current - flags string as reported by `CONFIG GET`
|
|
648
|
+
*/
|
|
649
|
+
private missingKeyspaceEvents;
|
|
650
|
+
/**
|
|
651
|
+
* Makes sure the server publishes the keyspace events this queue listens
|
|
652
|
+
* for, preserving whatever else is already configured.
|
|
653
|
+
*
|
|
654
|
+
* @remarks
|
|
655
|
+
* Flags configured out of band — by an operator, or by other code sharing
|
|
656
|
+
* the same Redis — are kept: only the missing ones are appended, and
|
|
657
|
+
* `CONFIG SET` is skipped entirely when nothing needs adding. When the
|
|
658
|
+
* `CONFIG` command is unavailable (e.g. AWS ElastiCache) the read fails and
|
|
659
|
+
* the error is reported without touching the configuration; enable
|
|
660
|
+
* `notify-keyspace-events` out of band in that case.
|
|
661
|
+
*/
|
|
662
|
+
private ensureKeyspaceEvents;
|
|
631
663
|
/**
|
|
632
664
|
* Setups watch a process on delayed messages
|
|
633
665
|
*/
|
package/src/RedisQueue.js
CHANGED
|
@@ -70,6 +70,20 @@ const RECONNECT_BASE_DELAY = 1000;
|
|
|
70
70
|
const RECONNECT_MAX_DELAY = 30000;
|
|
71
71
|
/** SCAN batch size used while sweeping keys */
|
|
72
72
|
const SCAN_COUNT = '1000';
|
|
73
|
+
/** Redis config parameter holding the keyspace-notification flags */
|
|
74
|
+
const NOTIFY_EVENTS_PARAM = 'notify-keyspace-events';
|
|
75
|
+
/**
|
|
76
|
+
* Keyspace-notification flags this queue depends on: `E` to receive
|
|
77
|
+
* `__keyevent@<db>__` notifications and `x` for expired-key events. Together
|
|
78
|
+
* they drive delayed-message delivery.
|
|
79
|
+
*/
|
|
80
|
+
const NOTIFY_EVENTS_REQUIRED = 'Ex';
|
|
81
|
+
/**
|
|
82
|
+
* Event classes Redis' `A` shortcut expands to — every class except the
|
|
83
|
+
* `K`/`E` delivery selectors and the special `m`/`n` classes. A server
|
|
84
|
+
* configured with `A` therefore already covers `x`.
|
|
85
|
+
*/
|
|
86
|
+
const NOTIFY_EVENTS_ALL = 'g$lshzxetd';
|
|
73
87
|
/**
|
|
74
88
|
* ioredis retry strategy that disables the built-in reconnection — this
|
|
75
89
|
* queue performs its own capped-backoff reconnection instead.
|
|
@@ -1364,6 +1378,71 @@ let RedisQueue = (() => {
|
|
|
1364
1378
|
delete this.safeCheckInterval;
|
|
1365
1379
|
}
|
|
1366
1380
|
}
|
|
1381
|
+
/**
|
|
1382
|
+
* Reads the keyspace-notification flags currently configured on the
|
|
1383
|
+
* server.
|
|
1384
|
+
*
|
|
1385
|
+
* @returns the raw flags string, or an empty string when notifications
|
|
1386
|
+
* are disabled
|
|
1387
|
+
*
|
|
1388
|
+
* @remarks
|
|
1389
|
+
* `CONFIG GET` replies as a flat `[name, value]` array over RESP2 and as a
|
|
1390
|
+
* map over RESP3, so both shapes are accepted.
|
|
1391
|
+
*/
|
|
1392
|
+
async currentKeyspaceEvents() {
|
|
1393
|
+
const reply = (await this.writer.config('GET', NOTIFY_EVENTS_PARAM));
|
|
1394
|
+
if (!reply) {
|
|
1395
|
+
return '';
|
|
1396
|
+
}
|
|
1397
|
+
let value;
|
|
1398
|
+
if (Array.isArray(reply)) {
|
|
1399
|
+
const at = reply.indexOf(NOTIFY_EVENTS_PARAM);
|
|
1400
|
+
// an unnamed parameter means the reply is not what was asked for,
|
|
1401
|
+
// and guessing the value out of it could only make things worse
|
|
1402
|
+
value = at < 0 ? undefined : reply[at + 1];
|
|
1403
|
+
}
|
|
1404
|
+
else {
|
|
1405
|
+
value = reply[NOTIFY_EVENTS_PARAM];
|
|
1406
|
+
}
|
|
1407
|
+
return typeof value === 'string' ? value : '';
|
|
1408
|
+
}
|
|
1409
|
+
/**
|
|
1410
|
+
* Returns the flags from {@link NOTIFY_EVENTS_REQUIRED} that the given
|
|
1411
|
+
* configuration does not already provide.
|
|
1412
|
+
*
|
|
1413
|
+
* @param current - flags string as reported by `CONFIG GET`
|
|
1414
|
+
*/
|
|
1415
|
+
missingKeyspaceEvents(current) {
|
|
1416
|
+
const covered = current.includes('A')
|
|
1417
|
+
? current + NOTIFY_EVENTS_ALL
|
|
1418
|
+
: current;
|
|
1419
|
+
return [...NOTIFY_EVENTS_REQUIRED]
|
|
1420
|
+
.filter(flag => !covered.includes(flag))
|
|
1421
|
+
.join('');
|
|
1422
|
+
}
|
|
1423
|
+
/**
|
|
1424
|
+
* Makes sure the server publishes the keyspace events this queue listens
|
|
1425
|
+
* for, preserving whatever else is already configured.
|
|
1426
|
+
*
|
|
1427
|
+
* @remarks
|
|
1428
|
+
* Flags configured out of band — by an operator, or by other code sharing
|
|
1429
|
+
* the same Redis — are kept: only the missing ones are appended, and
|
|
1430
|
+
* `CONFIG SET` is skipped entirely when nothing needs adding. When the
|
|
1431
|
+
* `CONFIG` command is unavailable (e.g. AWS ElastiCache) the read fails and
|
|
1432
|
+
* the error is reported without touching the configuration; enable
|
|
1433
|
+
* `notify-keyspace-events` out of band in that case.
|
|
1434
|
+
*/
|
|
1435
|
+
async ensureKeyspaceEvents() {
|
|
1436
|
+
const current = await this.currentKeyspaceEvents();
|
|
1437
|
+
const missing = this.missingKeyspaceEvents(current);
|
|
1438
|
+
if (!missing) {
|
|
1439
|
+
this.verbose(`Keyspace events "${current}" already cover ` +
|
|
1440
|
+
`"${NOTIFY_EVENTS_REQUIRED}", keeping them as is`);
|
|
1441
|
+
return;
|
|
1442
|
+
}
|
|
1443
|
+
this.verbose(`Adding "${missing}" to keyspace events "${current}"`);
|
|
1444
|
+
await this.writer.config('SET', NOTIFY_EVENTS_PARAM, current + missing);
|
|
1445
|
+
}
|
|
1367
1446
|
/**
|
|
1368
1447
|
* Setups watch a process on delayed messages
|
|
1369
1448
|
*/
|
|
@@ -1371,14 +1450,7 @@ let RedisQueue = (() => {
|
|
|
1371
1450
|
if (!this.writer || !this.watcher || this.watcher.__ready__) {
|
|
1372
1451
|
return this;
|
|
1373
1452
|
}
|
|
1374
|
-
|
|
1375
|
-
this.writer
|
|
1376
|
-
.config('SET', 'notify-keyspace-events', 'Ex')
|
|
1377
|
-
.catch((err) => this.emitError('OnConfig', 'events config error', err));
|
|
1378
|
-
}
|
|
1379
|
-
catch (err) {
|
|
1380
|
-
this.emitError('OnConfig', 'events config error', err);
|
|
1381
|
-
}
|
|
1453
|
+
this.ensureKeyspaceEvents().catch((err) => this.emitError('OnConfig', 'events config error', err));
|
|
1382
1454
|
this.watcher.on('pmessage', this.onWatchMessage.bind(this));
|
|
1383
1455
|
this.watcher
|
|
1384
1456
|
.psubscribe('__keyevent@0__:expired', `${this.options.prefix}:delayed:*`)
|