@venizia/ignis-helpers 0.4.8-11 → 0.4.8-12
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/esm/modules/queue/bullmq/helper.d.ts +14 -1
- package/dist/esm/modules/queue/bullmq/helper.js +52 -3
- package/dist/esm/modules/queue/bullmq/helper.js.map +1 -1
- package/dist/esm/modules/redis/base/abstract.helper.js +7 -1
- package/dist/esm/modules/redis/base/abstract.helper.js.map +1 -1
- package/dist/esm/modules/redis/common/types.d.ts +2 -0
- package/dist/esm/modules/redis/common/types.js.map +1 -1
- package/dist/esm/modules/redis/single/single.helper.js +2 -1
- package/dist/esm/modules/redis/single/single.helper.js.map +1 -1
- package/package.json +3 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseHelper } from '../../base.js';
|
|
2
|
-
import { type IRedisHelper } from '../../redis/index.js';
|
|
2
|
+
import { type IRedisHelper, type TRedisClient } from '../../redis/index.js';
|
|
3
3
|
import type { Job, Processor, Queue, QueueOptions, Worker, WorkerOptions } from 'bullmq';
|
|
4
4
|
import { type TBullQueueRole } from '../common/index.js';
|
|
5
5
|
/** Options for {@link BullMQHelper}. `role` decides whether a `Queue` or a `Worker` is built. */
|
|
@@ -46,7 +46,12 @@ export declare class BullMQHelper<TQueueElement = unknown, TQueueResult = unknow
|
|
|
46
46
|
protected onWorkerDataCompleted?: (job: Job<TQueueElement, TQueueResult>, result: TQueueResult) => Promise<void>;
|
|
47
47
|
protected onWorkerDataFail?: (job: Job<TQueueElement, TQueueResult> | undefined, error: Error) => Promise<void>;
|
|
48
48
|
private readonly bullmqModule?;
|
|
49
|
+
private isClosing;
|
|
50
|
+
/** Every duplicate this helper handed to BullMQ: BullMQ never quits a client it is given, so `close()` does. */
|
|
51
|
+
private readonly duplicates;
|
|
49
52
|
constructor(options: IBullMQOptions<TQueueElement, TQueueResult>);
|
|
53
|
+
/** BullMQ never reconnects a client: once ioredis stops reconnecting (`maxRetry` attempts used up) it is `end` for good, no job moves, and nothing else says so. */
|
|
54
|
+
protected reportClientEnded(): void;
|
|
50
55
|
static newInstance<T = unknown, R = unknown>(opts: IBullMQOptions<T, R>): BullMQHelper<T, R>;
|
|
51
56
|
/** Structural, never `instanceof`: ioredis is an optional peer, and a second copy fails `instanceof` anyway. */
|
|
52
57
|
protected isClusterClient(): boolean;
|
|
@@ -56,6 +61,12 @@ export declare class BullMQHelper<TQueueElement = unknown, TQueueResult = unknow
|
|
|
56
61
|
protected queueOptionsFor(opts: {
|
|
57
62
|
queueName: string;
|
|
58
63
|
}): QueueOptions;
|
|
64
|
+
/**
|
|
65
|
+
* The connection BullMQ owns: a duplicate of the helper's client, so the queue or worker connects it by itself
|
|
66
|
+
* whatever state the shared client is in. BullMQ treats a client it is handed as shared and never quits it, so the
|
|
67
|
+
* helper keeps the duplicate and quits it in `close()`.
|
|
68
|
+
*/
|
|
69
|
+
protected createConnection(): TRedisClient;
|
|
59
70
|
/** Full `Worker` options: `this.workerOptions`, then the connection/concurrency/lock fields the helper owns - in that precedence order. */
|
|
60
71
|
protected workerOptionsFor(opts: {
|
|
61
72
|
queueName: string;
|
|
@@ -74,6 +85,8 @@ export declare class BullMQHelper<TQueueElement = unknown, TQueueResult = unknow
|
|
|
74
85
|
}): Worker<TQueueElement, TQueueResult>;
|
|
75
86
|
configureWorker(): void;
|
|
76
87
|
configure(): void;
|
|
88
|
+
/** `quit()` waits for the replies in flight; a client BullMQ already closed is left alone. */
|
|
89
|
+
private static release;
|
|
77
90
|
close(): Promise<void>;
|
|
78
91
|
}
|
|
79
92
|
//# sourceMappingURL=helper.d.ts.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BaseHelper } from '../../base.js';
|
|
2
2
|
import { getError } from '../../error/index.js';
|
|
3
|
+
import { RedisDefaults } from '../../redis/index.js';
|
|
3
4
|
import { ErrorUtility } from '../../../utilities/error.utility.js';
|
|
4
5
|
import { ModuleUtility } from '../../../utilities/module.utility.js';
|
|
5
6
|
import { BullMQDefaults, BullQueueRoles, HookUtility } from '../common/index.js';
|
|
@@ -10,6 +11,9 @@ import { BullMQDefaults, BullQueueRoles, HookUtility } from '../common/index.js'
|
|
|
10
11
|
export class BullMQHelper extends BaseHelper {
|
|
11
12
|
constructor(options) {
|
|
12
13
|
super({ scope: BullMQHelper.name, identifier: options.identifier });
|
|
14
|
+
this.isClosing = false;
|
|
15
|
+
/** Every duplicate this helper handed to BullMQ: BullMQ never quits a client it is given, so `close()` does. */
|
|
16
|
+
this.duplicates = [];
|
|
13
17
|
const { queueName, redisConnection, role, numberOfWorker = BullMQDefaults.NUMBER_OF_WORKER, lockDuration = BullMQDefaults.LOCK_DURATION_MS, queueOptions, workerOptions, onWorkerData, onWorkerDataCompleted, onWorkerDataFail, module, } = options;
|
|
14
18
|
this.bullmqModule = module;
|
|
15
19
|
this.queueName = queueName;
|
|
@@ -24,6 +28,12 @@ export class BullMQHelper extends BaseHelper {
|
|
|
24
28
|
this.onWorkerDataFail = onWorkerDataFail;
|
|
25
29
|
this.configure();
|
|
26
30
|
}
|
|
31
|
+
/** BullMQ never reconnects a client: once ioredis stops reconnecting (`maxRetry` attempts used up) it is `end` for good, no job moves, and nothing else says so. */
|
|
32
|
+
reportClientEnded() {
|
|
33
|
+
this.logger
|
|
34
|
+
.for(this.reportClientEnded.name)
|
|
35
|
+
.error('The Redis client ended, so BullMQ can no longer move jobs on queue %s | ioredis stopped reconnecting after maxRetry attempts | Back BullMQ with a helper whose maxRetry is %d (forever) | ID: %s', this.queueName, RedisDefaults.RETRY_FOREVER, this.identifier);
|
|
36
|
+
}
|
|
27
37
|
static newInstance(opts) {
|
|
28
38
|
return new BullMQHelper(opts);
|
|
29
39
|
}
|
|
@@ -68,10 +78,24 @@ export class BullMQHelper extends BaseHelper {
|
|
|
68
78
|
removeOnFail: true,
|
|
69
79
|
},
|
|
70
80
|
...this.queueOptions,
|
|
71
|
-
|
|
72
|
-
connection: this.redisConnection.getClient(),
|
|
81
|
+
connection: this.createConnection(),
|
|
73
82
|
};
|
|
74
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* The connection BullMQ owns: a duplicate of the helper's client, so the queue or worker connects it by itself
|
|
86
|
+
* whatever state the shared client is in. BullMQ treats a client it is handed as shared and never quits it, so the
|
|
87
|
+
* helper keeps the duplicate and quits it in `close()`.
|
|
88
|
+
*/
|
|
89
|
+
createConnection() {
|
|
90
|
+
const connection = this.redisConnection.duplicateClient();
|
|
91
|
+
this.duplicates.push(connection);
|
|
92
|
+
connection.once('end', () => {
|
|
93
|
+
if (!this.isClosing) {
|
|
94
|
+
this.reportClientEnded();
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
return connection;
|
|
98
|
+
}
|
|
75
99
|
/** Full `Worker` options: `this.workerOptions`, then the connection/concurrency/lock fields the helper owns - in that precedence order. */
|
|
76
100
|
workerOptionsFor(opts) {
|
|
77
101
|
this.logger
|
|
@@ -79,7 +103,7 @@ export class BullMQHelper extends BaseHelper {
|
|
|
79
103
|
.debug('Building worker options | Queue: %s | ID: %s', opts.queueName, this.identifier);
|
|
80
104
|
return {
|
|
81
105
|
...this.workerOptions,
|
|
82
|
-
connection: this.
|
|
106
|
+
connection: this.createConnection(),
|
|
83
107
|
concurrency: this.numberOfWorker,
|
|
84
108
|
lockDuration: this.lockDuration,
|
|
85
109
|
};
|
|
@@ -158,7 +182,21 @@ export class BullMQHelper extends BaseHelper {
|
|
|
158
182
|
}
|
|
159
183
|
}
|
|
160
184
|
}
|
|
185
|
+
/** `quit()` waits for the replies in flight; a client BullMQ already closed is left alone. */
|
|
186
|
+
static async release(opts) {
|
|
187
|
+
const { connection } = opts;
|
|
188
|
+
if (connection.status === 'end') {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
try {
|
|
192
|
+
await connection.quit();
|
|
193
|
+
}
|
|
194
|
+
catch {
|
|
195
|
+
connection.disconnect();
|
|
196
|
+
}
|
|
197
|
+
}
|
|
161
198
|
async close() {
|
|
199
|
+
this.isClosing = true;
|
|
162
200
|
const failures = [];
|
|
163
201
|
// Both connections must be released even when the first close fails - otherwise a failing worker close silently leaks the queue's Redis connection forever.
|
|
164
202
|
try {
|
|
@@ -179,6 +217,17 @@ export class BullMQHelper extends BaseHelper {
|
|
|
179
217
|
.error('Error closing BullMQ queue: %s | ID: %s', error, this.identifier);
|
|
180
218
|
failures.push(ErrorUtility.toError({ error }).message);
|
|
181
219
|
}
|
|
220
|
+
for (const connection of this.duplicates.splice(0)) {
|
|
221
|
+
try {
|
|
222
|
+
await BullMQHelper.release({ connection });
|
|
223
|
+
}
|
|
224
|
+
catch (error) {
|
|
225
|
+
this.logger
|
|
226
|
+
.for(this.close.name)
|
|
227
|
+
.error('Error closing the BullMQ connection: %s | ID: %s', error, this.identifier);
|
|
228
|
+
failures.push(ErrorUtility.toError({ error }).message);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
182
231
|
if (failures.length) {
|
|
183
232
|
throw getError({
|
|
184
233
|
message: `[close][${this.identifier}] Failed to close BullMQ helper | Errors: ${failures.join(' | ')}`,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../../../../../src/modules/queue/bullmq/helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE3D,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,WAAW,EAAuB,MAAM,WAAW,CAAC;AAuC7F;;;GAGG;AACH,MAAM,OAAO,YAA8D,SAAQ,UAAU;IA2B3F,YAAY,OAAoD;QAC9D,KAAK,CAAC,EAAE,KAAK,EAAE,YAAY,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,E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AK,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC;QACzD,CAAC;QAED,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,CAAC;QAC5B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,MAAM;iBACR,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;iBACpB,KAAK,CAAC,yCAAyC,EAAE,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;YAC5E,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC;QACzD,CAAC;QAED,IAAI,QAAQ,CAAC,MAAM,EAAE,CAAC;YACpB,MAAM,QAAQ,CAAC;gBACb,OAAO,EAAE,WAAW,IAAI,CAAC,UAAU,6CAA6C,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;aACvG,CAAC,CAAC;QACL,CAAC;QAED,IAAI,CAAC,MAAM;aACR,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;aACpB,IAAI,CAAC,4CAA4C,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IACzE,CAAC;CACF","sourcesContent":["import { BaseHelper } from '@/modules/base';\nimport { getError } from '@/modules/error';\nimport { type IRedisHelper } from '@/modules/redis';\nimport { ErrorUtility } from '@/utilities/error.utility';\nimport { ModuleUtility } from '@/utilities/module.utility';\nimport type { Job, Processor, Queue, QueueOptions, Worker, WorkerOptions } from 'bullmq';\nimport { BullMQDefaults, BullQueueRoles, HookUtility, type TBullQueueRole } from '../common';\n\n/** Options for {@link BullMQHelper}. `role` decides whether a `Queue` or a `Worker` is built. */\nexport interface IBullMQOptions<TQueueElement = unknown, TQueueResult = unknown> {\n queueName: string;\n identifier: string;\n role: TBullQueueRole;\n redisConnection: IRedisHelper;\n\n /** `bullmq` itself, for a `bun build --compile` binary that has no `node_modules` to load it from. Omitted, it is loaded when a queue or worker is built. */\n module?: typeof import('bullmq');\n\n /**\n * Worker concurrency.\n * @default BullMQDefaults.NUMBER_OF_WORKER\n */\n numberOfWorker?: number;\n /**\n * How long a worker holds a job's lock, in milliseconds.\n * @default BullMQDefaults.LOCK_DURATION_MS\n */\n lockDuration?: number;\n\n /** Merged over the framework defaults, under the fields the helper owns (`connection`) - see `queueOptionsFor`. */\n queueOptions?: Omit<QueueOptions, 'connection'>;\n /** Merged under the fields the helper owns (`connection`, `concurrency`, `lockDuration`) - see `workerOptionsFor`. */\n workerOptions?: Omit<WorkerOptions, 'connection' | 'concurrency' | 'lockDuration'>;\n\n onWorkerData?: (job: Job<TQueueElement, TQueueResult>) => Promise<TQueueResult>;\n onWorkerDataCompleted?: (\n job: Job<TQueueElement, TQueueResult>,\n result: TQueueResult,\n ) => Promise<void>;\n onWorkerDataFail?: (\n job: Job<TQueueElement, TQueueResult> | undefined,\n error: Error,\n ) => Promise<void>;\n}\n\n/**\n * Wraps a BullMQ `Queue` or `Worker` (per `role`) on one Redis connection.\n * Worker concurrency is `numberOfWorker`; `lockDuration` is in milliseconds.\n */\nexport class BullMQHelper<TQueueElement = unknown, TQueueResult = unknown> extends BaseHelper {\n protected queueName: string;\n protected role: TBullQueueRole;\n protected redisConnection: IRedisHelper;\n\n queue: Queue<TQueueElement, TQueueResult>;\n worker: Worker<TQueueElement, TQueueResult>;\n\n protected numberOfWorker: number;\n protected lockDuration: number;\n\n protected queueOptions?: Omit<QueueOptions, 'connection'>;\n protected workerOptions?: Omit<WorkerOptions, 'connection' | 'concurrency' | 'lockDuration'>;\n\n protected onWorkerData?: (job: Job<TQueueElement, TQueueResult>) => Promise<TQueueResult>;\n protected onWorkerDataCompleted?: (\n job: Job<TQueueElement, TQueueResult>,\n result: TQueueResult,\n ) => Promise<void>;\n\n protected onWorkerDataFail?: (\n job: Job<TQueueElement, TQueueResult> | undefined,\n error: Error,\n ) => Promise<void>;\n\n private readonly bullmqModule?: typeof import('bullmq');\n\n constructor(options: IBullMQOptions<TQueueElement, TQueueResult>) {\n super({ scope: BullMQHelper.name, identifier: options.identifier });\n const {\n queueName,\n redisConnection,\n role,\n numberOfWorker = BullMQDefaults.NUMBER_OF_WORKER,\n lockDuration = BullMQDefaults.LOCK_DURATION_MS,\n queueOptions,\n workerOptions,\n onWorkerData,\n onWorkerDataCompleted,\n onWorkerDataFail,\n module,\n } = options;\n\n this.bullmqModule = module;\n\n this.queueName = queueName;\n this.role = role;\n this.redisConnection = redisConnection;\n\n this.numberOfWorker = numberOfWorker;\n this.lockDuration = lockDuration;\n\n this.queueOptions = queueOptions;\n this.workerOptions = workerOptions;\n\n this.onWorkerData = onWorkerData;\n this.onWorkerDataCompleted = onWorkerDataCompleted;\n this.onWorkerDataFail = onWorkerDataFail;\n\n this.configure();\n }\n\n static newInstance<T = unknown, R = unknown>(opts: IBullMQOptions<T, R>) {\n return new BullMQHelper<T, R>(opts);\n }\n\n /** Structural, never `instanceof`: ioredis is an optional peer, and a second copy fails `instanceof` anyway. */\n protected isClusterClient(): boolean {\n const client = Object(this.redisConnection.getClient());\n\n if (Reflect.get(client, 'isCluster') === true) {\n return true;\n }\n\n return typeof Reflect.get(client, 'nodes') === 'function';\n }\n\n protected resolveQueueName(): string {\n if (this.isClusterClient() && !this.queueName.startsWith('{')) {\n return `{${this.queueName}}`;\n }\n\n return this.queueName;\n }\n\n configureQueue() {\n if (!this.queueName) {\n this.logger\n .for(this.configureQueue.name)\n .error('Invalid queue name | ID: %s', this.identifier);\n\n return;\n }\n\n const queueName = this.resolveQueueName();\n this.queue = this.buildQueue({ queueName });\n\n // An 'error' event without a listener is re-thrown by EventEmitter - a Redis hiccup would take the whole process down.\n this.queue.on('error', (error) => {\n this.logger\n .for('queue-error')\n .error(\n 'queue: %s | Queue error! Error: %s | ID: %s',\n this.queueName,\n error,\n this.identifier,\n );\n });\n }\n\n /** Full `Queue` options: framework defaults, then `this.queueOptions`, then the connection the helper owns - in that precedence order. */\n protected queueOptionsFor(opts: { queueName: string }): QueueOptions {\n this.logger\n .for(this.queueOptionsFor.name)\n .debug('Building queue options | Queue: %s | ID: %s', opts.queueName, this.identifier);\n\n return {\n defaultJobOptions: {\n removeOnComplete: true,\n removeOnFail: true,\n },\n ...this.queueOptions,\n // The helper's own client, never a duplicate: BullMQ marks a client it is handed as shared and never quits it, so a duplicate would leak one connection per queue and worker. BullMQ opens (and closes) its own blocking connection.\n connection: this.redisConnection.getClient(),\n };\n }\n\n /** Full `Worker` options: `this.workerOptions`, then the connection/concurrency/lock fields the helper owns - in that precedence order. */\n protected workerOptionsFor(opts: {\n queueName: string;\n processor: Processor<TQueueElement, TQueueResult>;\n }): WorkerOptions {\n this.logger\n .for(this.workerOptionsFor.name)\n .debug('Building worker options | Queue: %s | ID: %s', opts.queueName, this.identifier);\n\n return {\n ...this.workerOptions,\n connection: this.redisConnection.getClient(),\n concurrency: this.numberOfWorker,\n lockDuration: this.lockDuration,\n };\n }\n\n /** `bullmq` is an optional peer: loaded when a queue or worker is built, not when this module is. */\n private loadBullMQ(): typeof import('bullmq') {\n return (\n this.bullmqModule ?? ModuleUtility.loadSync<typeof import('bullmq')>({ module: 'bullmq' })\n );\n }\n\n /** Client factory seam - overridden in tests to run the helper without Redis. */\n protected buildQueue(opts: { queueName: string }): Queue<TQueueElement, TQueueResult> {\n const bullmq = this.loadBullMQ();\n\n return new bullmq.Queue<TQueueElement, TQueueResult>(\n opts.queueName,\n this.queueOptionsFor(opts),\n );\n }\n\n /** Client factory seam - overridden in tests to run the helper without Redis. */\n protected buildWorker(opts: {\n queueName: string;\n processor: Processor<TQueueElement, TQueueResult>;\n }): Worker<TQueueElement, TQueueResult> {\n const bullmq = this.loadBullMQ();\n\n return new bullmq.Worker<TQueueElement, TQueueResult>(\n opts.queueName,\n opts.processor,\n this.workerOptionsFor(opts),\n );\n }\n\n configureWorker() {\n if (!this.queueName) {\n this.logger\n .for(this.configureWorker.name)\n .error('Invalid worker name | ID: %s', this.identifier);\n\n return;\n }\n\n const queueName = this.resolveQueueName();\n this.worker = this.buildWorker({\n queueName,\n processor: async (job) => {\n if (this.onWorkerData) {\n return this.onWorkerData(job);\n }\n\n const { id, name, data } = job;\n this.logger\n .for('onWorkerData')\n .info(\n 'queue: %s | id: %s | name: %s | data: %j | ID: %s',\n this.queueName,\n id,\n name,\n data,\n this.identifier,\n );\n\n return undefined as TQueueResult;\n },\n });\n\n this.worker.on('completed', (job, result) => {\n HookUtility.invoke({\n logger: this.logger,\n scope: 'worker-completed',\n execution: () => this.onWorkerDataCompleted?.(job, result),\n });\n });\n\n this.worker.on('failed', (job, reason) => {\n HookUtility.invoke({\n logger: this.logger,\n scope: 'worker-failed',\n execution: () => this.onWorkerDataFail?.(job, reason),\n });\n });\n\n // An 'error' event without a listener is re-thrown by EventEmitter - a Redis hiccup would take the whole process down.\n this.worker.on('error', (error) => {\n this.logger\n .for('worker-error')\n .error(\n 'queue: %s | Worker error! Error: %s | ID: %s',\n this.queueName,\n error,\n this.identifier,\n );\n });\n }\n\n configure() {\n if (!this.role) {\n this.logger\n .for(this.configure.name)\n .error(\n 'Invalid client role to configure | Valid roles: [queue|worker] | ID: %s',\n this.identifier,\n );\n\n return;\n }\n\n switch (this.role) {\n case BullQueueRoles.QUEUE: {\n this.configureQueue();\n break;\n }\n case BullQueueRoles.WORKER: {\n this.configureWorker();\n break;\n }\n }\n }\n\n async close() {\n const failures: string[] = [];\n\n // Both connections must be released even when the first close fails - otherwise a failing worker close silently leaks the queue's Redis connection forever.\n try {\n await this.worker?.close();\n } catch (error) {\n this.logger\n .for(this.close.name)\n .error('Error closing BullMQ worker: %s | ID: %s', error, this.identifier);\n failures.push(ErrorUtility.toError({ error }).message);\n }\n\n try {\n await this.queue?.close();\n } catch (error) {\n this.logger\n .for(this.close.name)\n .error('Error closing BullMQ queue: %s | ID: %s', error, this.identifier);\n failures.push(ErrorUtility.toError({ error }).message);\n }\n\n if (failures.length) {\n throw getError({\n message: `[close][${this.identifier}] Failed to close BullMQ helper | Errors: ${failures.join(' | ')}`,\n });\n }\n\n this.logger\n .for(this.close.name)\n .info('BullMQ helper closed successfully | ID: %s', this.identifier);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../../../../../src/modules/queue/bullmq/helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAqB,aAAa,EAAqB,MAAM,iBAAiB,CAAC;AACtF,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE3D,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,WAAW,EAAuB,MAAM,WAAW,CAAC;AAuC7F;;;GAGG;AACH,MAAM,OAAO,YAA8D,SAAQ,UAAU;IA8B3F,YAAY,OAAoD;QAC9D,KAAK,CAAC,EAAE,KAAK,EAAE,YAAY,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;QAL9D,cAAS,GAAG,KAAK,CAAC;QAC1B,gHAAgH;QAC/F,eAAU,GAAmB,EAAE,CAAC;QAI/C,MAAM,EACJ,SAAS,EACT,eAAe,EACf,IAAI,EACJ,cAAc,GAAG,cAAc,CAAC,gBAAgB,EAChD,YAAY,GAAG,cAAc,CAAC,gBAAgB,EAC9C,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,qBAAqB,EACrB,gBAAgB,EAChB,MAAM,GACP,GAAG,OAAO,CAAC;QAEZ,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC;QAE3B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QAEvC,IAAI,CAAC,cAAc,GAAG,cAAc,CA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AK,CAAC,kDAAkD,EAAE,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;gBACrF,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC;YACzD,CAAC;QACH,CAAC;QAED,IAAI,QAAQ,CAAC,MAAM,EAAE,CAAC;YACpB,MAAM,QAAQ,CAAC;gBACb,OAAO,EAAE,WAAW,IAAI,CAAC,UAAU,6CAA6C,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;aACvG,CAAC,CAAC;QACL,CAAC;QAED,IAAI,CAAC,MAAM;aACR,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;aACpB,IAAI,CAAC,4CAA4C,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IACzE,CAAC;CACF","sourcesContent":["import { BaseHelper } from '@/modules/base';\nimport { getError } from '@/modules/error';\nimport { type IRedisHelper, RedisDefaults, type TRedisClient } from '@/modules/redis';\nimport { ErrorUtility } from '@/utilities/error.utility';\nimport { ModuleUtility } from '@/utilities/module.utility';\nimport type { Job, Processor, Queue, QueueOptions, Worker, WorkerOptions } from 'bullmq';\nimport { BullMQDefaults, BullQueueRoles, HookUtility, type TBullQueueRole } from '../common';\n\n/** Options for {@link BullMQHelper}. `role` decides whether a `Queue` or a `Worker` is built. */\nexport interface IBullMQOptions<TQueueElement = unknown, TQueueResult = unknown> {\n queueName: string;\n identifier: string;\n role: TBullQueueRole;\n redisConnection: IRedisHelper;\n\n /** `bullmq` itself, for a `bun build --compile` binary that has no `node_modules` to load it from. Omitted, it is loaded when a queue or worker is built. */\n module?: typeof import('bullmq');\n\n /**\n * Worker concurrency.\n * @default BullMQDefaults.NUMBER_OF_WORKER\n */\n numberOfWorker?: number;\n /**\n * How long a worker holds a job's lock, in milliseconds.\n * @default BullMQDefaults.LOCK_DURATION_MS\n */\n lockDuration?: number;\n\n /** Merged over the framework defaults, under the fields the helper owns (`connection`) - see `queueOptionsFor`. */\n queueOptions?: Omit<QueueOptions, 'connection'>;\n /** Merged under the fields the helper owns (`connection`, `concurrency`, `lockDuration`) - see `workerOptionsFor`. */\n workerOptions?: Omit<WorkerOptions, 'connection' | 'concurrency' | 'lockDuration'>;\n\n onWorkerData?: (job: Job<TQueueElement, TQueueResult>) => Promise<TQueueResult>;\n onWorkerDataCompleted?: (\n job: Job<TQueueElement, TQueueResult>,\n result: TQueueResult,\n ) => Promise<void>;\n onWorkerDataFail?: (\n job: Job<TQueueElement, TQueueResult> | undefined,\n error: Error,\n ) => Promise<void>;\n}\n\n/**\n * Wraps a BullMQ `Queue` or `Worker` (per `role`) on one Redis connection.\n * Worker concurrency is `numberOfWorker`; `lockDuration` is in milliseconds.\n */\nexport class BullMQHelper<TQueueElement = unknown, TQueueResult = unknown> extends BaseHelper {\n protected queueName: string;\n protected role: TBullQueueRole;\n protected redisConnection: IRedisHelper;\n\n queue: Queue<TQueueElement, TQueueResult>;\n worker: Worker<TQueueElement, TQueueResult>;\n\n protected numberOfWorker: number;\n protected lockDuration: number;\n\n protected queueOptions?: Omit<QueueOptions, 'connection'>;\n protected workerOptions?: Omit<WorkerOptions, 'connection' | 'concurrency' | 'lockDuration'>;\n\n protected onWorkerData?: (job: Job<TQueueElement, TQueueResult>) => Promise<TQueueResult>;\n protected onWorkerDataCompleted?: (\n job: Job<TQueueElement, TQueueResult>,\n result: TQueueResult,\n ) => Promise<void>;\n\n protected onWorkerDataFail?: (\n job: Job<TQueueElement, TQueueResult> | undefined,\n error: Error,\n ) => Promise<void>;\n\n private readonly bullmqModule?: typeof import('bullmq');\n private isClosing = false;\n /** Every duplicate this helper handed to BullMQ: BullMQ never quits a client it is given, so `close()` does. */\n private readonly duplicates: TRedisClient[] = [];\n\n constructor(options: IBullMQOptions<TQueueElement, TQueueResult>) {\n super({ scope: BullMQHelper.name, identifier: options.identifier });\n const {\n queueName,\n redisConnection,\n role,\n numberOfWorker = BullMQDefaults.NUMBER_OF_WORKER,\n lockDuration = BullMQDefaults.LOCK_DURATION_MS,\n queueOptions,\n workerOptions,\n onWorkerData,\n onWorkerDataCompleted,\n onWorkerDataFail,\n module,\n } = options;\n\n this.bullmqModule = module;\n\n this.queueName = queueName;\n this.role = role;\n this.redisConnection = redisConnection;\n\n this.numberOfWorker = numberOfWorker;\n this.lockDuration = lockDuration;\n\n this.queueOptions = queueOptions;\n this.workerOptions = workerOptions;\n\n this.onWorkerData = onWorkerData;\n this.onWorkerDataCompleted = onWorkerDataCompleted;\n this.onWorkerDataFail = onWorkerDataFail;\n\n this.configure();\n }\n\n /** BullMQ never reconnects a client: once ioredis stops reconnecting (`maxRetry` attempts used up) it is `end` for good, no job moves, and nothing else says so. */\n protected reportClientEnded() {\n this.logger\n .for(this.reportClientEnded.name)\n .error(\n 'The Redis client ended, so BullMQ can no longer move jobs on queue %s | ioredis stopped reconnecting after maxRetry attempts | Back BullMQ with a helper whose maxRetry is %d (forever) | ID: %s',\n this.queueName,\n RedisDefaults.RETRY_FOREVER,\n this.identifier,\n );\n }\n\n static newInstance<T = unknown, R = unknown>(opts: IBullMQOptions<T, R>) {\n return new BullMQHelper<T, R>(opts);\n }\n\n /** Structural, never `instanceof`: ioredis is an optional peer, and a second copy fails `instanceof` anyway. */\n protected isClusterClient(): boolean {\n const client = Object(this.redisConnection.getClient());\n\n if (Reflect.get(client, 'isCluster') === true) {\n return true;\n }\n\n return typeof Reflect.get(client, 'nodes') === 'function';\n }\n\n protected resolveQueueName(): string {\n if (this.isClusterClient() && !this.queueName.startsWith('{')) {\n return `{${this.queueName}}`;\n }\n\n return this.queueName;\n }\n\n configureQueue() {\n if (!this.queueName) {\n this.logger\n .for(this.configureQueue.name)\n .error('Invalid queue name | ID: %s', this.identifier);\n\n return;\n }\n\n const queueName = this.resolveQueueName();\n this.queue = this.buildQueue({ queueName });\n\n // An 'error' event without a listener is re-thrown by EventEmitter - a Redis hiccup would take the whole process down.\n this.queue.on('error', (error) => {\n this.logger\n .for('queue-error')\n .error(\n 'queue: %s | Queue error! Error: %s | ID: %s',\n this.queueName,\n error,\n this.identifier,\n );\n });\n }\n\n /** Full `Queue` options: framework defaults, then `this.queueOptions`, then the connection the helper owns - in that precedence order. */\n protected queueOptionsFor(opts: { queueName: string }): QueueOptions {\n this.logger\n .for(this.queueOptionsFor.name)\n .debug('Building queue options | Queue: %s | ID: %s', opts.queueName, this.identifier);\n\n return {\n defaultJobOptions: {\n removeOnComplete: true,\n removeOnFail: true,\n },\n ...this.queueOptions,\n connection: this.createConnection(),\n };\n }\n\n /**\n * The connection BullMQ owns: a duplicate of the helper's client, so the queue or worker connects it by itself\n * whatever state the shared client is in. BullMQ treats a client it is handed as shared and never quits it, so the\n * helper keeps the duplicate and quits it in `close()`.\n */\n protected createConnection(): TRedisClient {\n const connection = this.redisConnection.duplicateClient();\n this.duplicates.push(connection);\n connection.once('end', () => {\n if (!this.isClosing) {\n this.reportClientEnded();\n }\n });\n\n return connection;\n }\n\n /** Full `Worker` options: `this.workerOptions`, then the connection/concurrency/lock fields the helper owns - in that precedence order. */\n protected workerOptionsFor(opts: {\n queueName: string;\n processor: Processor<TQueueElement, TQueueResult>;\n }): WorkerOptions {\n this.logger\n .for(this.workerOptionsFor.name)\n .debug('Building worker options | Queue: %s | ID: %s', opts.queueName, this.identifier);\n\n return {\n ...this.workerOptions,\n connection: this.createConnection(),\n concurrency: this.numberOfWorker,\n lockDuration: this.lockDuration,\n };\n }\n\n /** `bullmq` is an optional peer: loaded when a queue or worker is built, not when this module is. */\n private loadBullMQ(): typeof import('bullmq') {\n return (\n this.bullmqModule ?? ModuleUtility.loadSync<typeof import('bullmq')>({ module: 'bullmq' })\n );\n }\n\n /** Client factory seam - overridden in tests to run the helper without Redis. */\n protected buildQueue(opts: { queueName: string }): Queue<TQueueElement, TQueueResult> {\n const bullmq = this.loadBullMQ();\n\n return new bullmq.Queue<TQueueElement, TQueueResult>(\n opts.queueName,\n this.queueOptionsFor(opts),\n );\n }\n\n /** Client factory seam - overridden in tests to run the helper without Redis. */\n protected buildWorker(opts: {\n queueName: string;\n processor: Processor<TQueueElement, TQueueResult>;\n }): Worker<TQueueElement, TQueueResult> {\n const bullmq = this.loadBullMQ();\n\n return new bullmq.Worker<TQueueElement, TQueueResult>(\n opts.queueName,\n opts.processor,\n this.workerOptionsFor(opts),\n );\n }\n\n configureWorker() {\n if (!this.queueName) {\n this.logger\n .for(this.configureWorker.name)\n .error('Invalid worker name | ID: %s', this.identifier);\n\n return;\n }\n\n const queueName = this.resolveQueueName();\n this.worker = this.buildWorker({\n queueName,\n processor: async (job) => {\n if (this.onWorkerData) {\n return this.onWorkerData(job);\n }\n\n const { id, name, data } = job;\n this.logger\n .for('onWorkerData')\n .info(\n 'queue: %s | id: %s | name: %s | data: %j | ID: %s',\n this.queueName,\n id,\n name,\n data,\n this.identifier,\n );\n\n return undefined as TQueueResult;\n },\n });\n\n this.worker.on('completed', (job, result) => {\n HookUtility.invoke({\n logger: this.logger,\n scope: 'worker-completed',\n execution: () => this.onWorkerDataCompleted?.(job, result),\n });\n });\n\n this.worker.on('failed', (job, reason) => {\n HookUtility.invoke({\n logger: this.logger,\n scope: 'worker-failed',\n execution: () => this.onWorkerDataFail?.(job, reason),\n });\n });\n\n // An 'error' event without a listener is re-thrown by EventEmitter - a Redis hiccup would take the whole process down.\n this.worker.on('error', (error) => {\n this.logger\n .for('worker-error')\n .error(\n 'queue: %s | Worker error! Error: %s | ID: %s',\n this.queueName,\n error,\n this.identifier,\n );\n });\n }\n\n configure() {\n if (!this.role) {\n this.logger\n .for(this.configure.name)\n .error(\n 'Invalid client role to configure | Valid roles: [queue|worker] | ID: %s',\n this.identifier,\n );\n\n return;\n }\n\n switch (this.role) {\n case BullQueueRoles.QUEUE: {\n this.configureQueue();\n break;\n }\n case BullQueueRoles.WORKER: {\n this.configureWorker();\n break;\n }\n }\n }\n\n /** `quit()` waits for the replies in flight; a client BullMQ already closed is left alone. */\n private static async release(opts: { connection: TRedisClient }) {\n const { connection } = opts;\n\n if (connection.status === 'end') {\n return;\n }\n\n try {\n await connection.quit();\n } catch {\n connection.disconnect();\n }\n }\n\n async close() {\n this.isClosing = true;\n const failures: string[] = [];\n\n // Both connections must be released even when the first close fails - otherwise a failing worker close silently leaks the queue's Redis connection forever.\n try {\n await this.worker?.close();\n } catch (error) {\n this.logger\n .for(this.close.name)\n .error('Error closing BullMQ worker: %s | ID: %s', error, this.identifier);\n failures.push(ErrorUtility.toError({ error }).message);\n }\n\n try {\n await this.queue?.close();\n } catch (error) {\n this.logger\n .for(this.close.name)\n .error('Error closing BullMQ queue: %s | ID: %s', error, this.identifier);\n failures.push(ErrorUtility.toError({ error }).message);\n }\n\n for (const connection of this.duplicates.splice(0)) {\n try {\n await BullMQHelper.release({ connection });\n } catch (error) {\n this.logger\n .for(this.close.name)\n .error('Error closing the BullMQ connection: %s | ID: %s', error, this.identifier);\n failures.push(ErrorUtility.toError({ error }).message);\n }\n }\n\n if (failures.length) {\n throw getError({\n message: `[close][${this.identifier}] Failed to close BullMQ helper | Errors: ${failures.join(' | ')}`,\n });\n }\n\n this.logger\n .for(this.close.name)\n .info('BullMQ helper closed successfully | ID: %s', this.identifier);\n }\n}\n"]}
|
|
@@ -87,7 +87,13 @@ export class AbstractRedisHelper extends BaseHelper {
|
|
|
87
87
|
return this.client.ping();
|
|
88
88
|
}
|
|
89
89
|
async connect() {
|
|
90
|
-
|
|
90
|
+
// `connect` is the cluster-only step between `connecting` and `ready`: ioredis refuses a second connect() there as well.
|
|
91
|
+
const invalidStatuses = [
|
|
92
|
+
'ready',
|
|
93
|
+
'reconnecting',
|
|
94
|
+
'connecting',
|
|
95
|
+
'connect',
|
|
96
|
+
];
|
|
91
97
|
if (invalidStatuses.includes(this.client.status)) {
|
|
92
98
|
this.logger
|
|
93
99
|
.for(this.connect.name)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abstract.helper.js","sourceRoot":"","sources":["../../../../../src/modules/redis/base/abstract.helper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AC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QACtD,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;QAEvB,IAAI,CAAC,KAAK,IAAI,aAAa,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;YACtD,MAAM,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAC;YAEzC,OAAO;QACT,CAAC;QAED,cAAc,CAAC,aAAa,CAAC;YAC3B,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,KAAK,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI;YAC5B,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;gBACzD,IAAI,KAAK,EAAE,CAAC;oBACV,MAAM,CAAC,KAAK,CAAC,kDAAkD,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;oBAE/E,OAAO;gBACT,CAAC;gBAED,MAAM,CAAC,IAAI,CAAC,kCAAkC,EAAE,KAAK,CAAC,CAAC;YACzD,CAAC,CAAC;SACH,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { ObjectUtility } from '@venizia/ignis-inversion';\nimport { PromiseUtility } from '@/utilities/promise.utility';\nimport { getError } from '@/modules/error';\nimport { LoggerFactory } from '@/modules/logger';\nimport { RetryHelper } from '@/modules/retry';\nimport { BaseHelper } from '@/modules/base';\nimport { type EventEmitter } from 'node:events';\nimport zlib from 'node:zlib';\nimport { RedisConcurrency, RedisDefaults } from './../common/constants';\nimport { type IRedisHelper } from './../common/interfaces';\nimport { type IRedisHelperCallbacks, type TRedisClient } from './../common/types';\n\n/** Registry symbol that marks an instance as a Redis helper; `isRedisHelper` tests for it. */\nexport const REDIS_HELPER_BRAND = Symbol.for('@venizia/ignis-helpers:abstract-redis-helper');\n\n/** Brand check, never `instanceof`: two installed copies of this package are two distinct classes, so a helper built by one is rejected by the other. `Symbol.for` is realm-keyed and survives that. */\nexport const isRedisHelper = (value: unknown): value is AbstractRedisHelper => {\n return typeof value === 'object' && value !== null && REDIS_HELPER_BRAND in value;\n};\n\n/** Base for the Redis helpers: wraps one ioredis client, logs its lifecycle events and forwards them to the `onInitialized`, `onConnected`, `onReady` and `onError` callbacks. Subclasses build the client. */\nexport class AbstractRedisHelper<ClientType extends TRedisClient = TRedisClient>\n extends BaseHelper\n implements IRedisHelper\n{\n /** Read by {@link isRedisHelper}. On the instance, so every subclass instance carries it. */\n readonly [REDIS_HELPER_BRAND] = true;\n\n client: ClientType;\n readonly name: string;\n\n constructor(\n opts: { scope: string; identifier: string; client: ClientType } & IRedisHelperCallbacks,\n ) {\n super({ scope: opts.scope, identifier: opts.identifier });\n\n this.name = opts.identifier;\n this.client = opts.client;\n\n const { onInitialized, onConnected, onReady, onError } = opts;\n const emitter = this.client as EventEmitter;\n\n emitter.on('connect', () => {\n this.logger.for('connect').info('Redis CONNECTED | Name: %s', this.name);\n onConnected?.({ name: this.name, helper: this });\n });\n\n emitter.on('ready', () => {\n this.logger.for('ready').info('Redis READY | Name: %s', this.name);\n onReady?.({ name: this.name, helper: this });\n });\n\n emitter.on('error', (error: Error) => {\n this.logger.for('error').error('Redis ERROR | Name: %s | Error: %s', this.name, error);\n onError?.({ name: this.name, helper: this, error });\n });\n\n emitter.on('reconnecting', () => {\n this.logger.for('reconnecting').warn('Redis client RECONNECTING | Name: %s', this.name);\n });\n\n onInitialized?.({ name: this.name, helper: this });\n }\n\n /** `maxRetry` is `0`, `RedisDefaults.RETRY_FOREVER` or a positive integer; anything else is a typo that would silently change how the client reconnects. */\n protected static assertMaxRetry(opts: { scope: string; name: string; maxRetry: number }) {\n const { scope, name, maxRetry } = opts;\n\n if (!Number.isInteger(maxRetry) || (maxRetry < 0 && maxRetry !== RedisDefaults.RETRY_FOREVER)) {\n throw getError({\n message: `[${scope}] maxRetry must be 0, ${RedisDefaults.RETRY_FOREVER} (forever) or a positive integer | name: ${name} | value: ${maxRetry}`,\n });\n }\n }\n\n /** The wait before each reconnect, then `undefined` once `maxRetry` attempts failed: ioredis stops and the helper logs it once. */\n protected static buildRetryStrategy(opts: { scope: string; name: string; maxRetry: number }) {\n const { scope, name, maxRetry } = opts;\n\n AbstractRedisHelper.assertMaxRetry(opts);\n\n return (attempt: number) => {\n if (maxRetry !== RedisDefaults.RETRY_FOREVER && attempt > maxRetry) {\n LoggerFactory.getLogger([scope, name])\n .for('retry')\n .error('Redis gave up reconnecting | Name: %s | maxRetry: %d', name, maxRetry);\n\n return undefined;\n }\n\n return RetryHelper.computeBackoffDelayMs({\n attempt,\n backoff: RedisDefaults.RECONNECT_BACKOFF,\n });\n };\n }\n\n protected static buildDefaultOpts(opts: { scope: string; name: string; maxRetry: number }) {\n return {\n showFriendlyErrorStack: true,\n maxRetriesPerRequest: null,\n retryStrategy: AbstractRedisHelper.buildRetryStrategy(opts),\n };\n }\n\n // --- Connection lifecycle (IRedisConnection) ---\n\n getClient() {\n return this.client;\n }\n\n duplicateClient(): TRedisClient {\n // ioredis 6 types `duplicate` per client; the `Redis | Cluster` union has no callable signature.\n const duplicable: { duplicate: () => TRedisClient } = this.client;\n\n return duplicable.duplicate();\n }\n\n ping() {\n return this.client.ping();\n }\n\n async connect() {\n const invalidStatuses: (typeof this.client.status)[] = ['ready', 'reconnecting', 'connecting'];\n\n if (invalidStatuses.includes(this.client.status)) {\n this.logger\n .for(this.connect.name)\n .info('status: %s | Invalid redis status to invoke connect', this.client.status);\n\n return false;\n }\n\n await this.client.connect();\n\n return this.client.status === 'ready';\n }\n\n async disconnect() {\n const invalidStatuses: (typeof this.client.status)[] = ['end', 'close'];\n\n if (invalidStatuses.includes(this.client.status)) {\n this.logger\n .for(this.disconnect.name)\n .info('status: %s | Invalid redis status to invoke disconnect', this.client.status);\n\n return false;\n }\n\n const reply = await this.client.quit();\n\n return reply === 'OK';\n }\n\n // --- Key lifecycle + counters (IRedisKey) ---\n\n exists(opts: { keys: Array<string> }): Promise<number> {\n const { keys } = opts;\n\n if (!keys.length) {\n return Promise.resolve(0);\n }\n\n return this.client.exists(...keys);\n }\n\n async expire(opts: { key: string; seconds: number }): Promise<boolean> {\n const { key, seconds } = opts;\n const result = await this.client.expire(key, seconds);\n\n return result === 1;\n }\n\n async expireAt(opts: { key: string; atEpochSeconds: number }): Promise<boolean> {\n const { key, atEpochSeconds } = opts;\n const result = await this.client.expireat(key, atEpochSeconds);\n\n return result === 1;\n }\n\n ttl(opts: { key: string }): Promise<number> {\n const { key } = opts;\n\n return this.client.ttl(key);\n }\n\n async persist(opts: { key: string }): Promise<boolean> {\n const { key } = opts;\n const result = await this.client.persist(key);\n\n return result === 1;\n }\n\n incr(opts: { key: string }): Promise<number> {\n const { key } = opts;\n\n return this.client.incr(key);\n }\n\n decr(opts: { key: string }): Promise<number> {\n const { key } = opts;\n\n return this.client.decr(key);\n }\n\n incrBy(opts: { key: string; value: number }): Promise<number> {\n const { key, value } = opts;\n\n return this.client.incrby(key, value);\n }\n\n decrBy(opts: { key: string; value: number }): Promise<number> {\n const { key, value } = opts;\n\n return this.client.decrby(key, value);\n }\n\n // --- Key-value (IRedisKeyValue) ---\n\n async set<T>(opts: {\n key: string;\n value: T;\n options?: { log?: boolean; expiresIn?: number };\n }): Promise<void> {\n const { key, value, options } = opts;\n\n const serialized = JSON.stringify(value);\n\n if (typeof options?.expiresIn === 'number' && options.expiresIn > 0) {\n await this.client.set(key, serialized, 'PX', options.expiresIn);\n } else {\n await this.client.set(key, serialized);\n }\n\n if (!options?.log) {\n return;\n }\n\n this.logger.for(this.set.name).info('Set key: %s | value: %s', key, serialized);\n }\n\n async get<T = string>(opts: {\n key: string;\n transform?: (input: string) => T;\n }): Promise<T | null> {\n const { key, transform } = opts;\n\n const value = await this.client.get(key);\n\n if (!value) {\n return null;\n }\n\n return transform ? transform(value) : (value as T);\n }\n\n del(opts: { keys: Array<string> }): Promise<number> {\n const { keys } = opts;\n\n if (!keys.length) {\n return Promise.resolve(0);\n }\n\n return this.client.del(keys);\n }\n\n getString(opts: { key: string }) {\n return this.get(opts);\n }\n\n getStrings(opts: { keys: Array<string> }) {\n return this.mGet(opts);\n }\n\n getObject<T>(opts: { key: string }) {\n return this.get<T>({\n ...opts,\n transform: (el: string) => JSON.parse(el),\n });\n }\n\n getObjects(opts: { keys: Array<string> }) {\n return this.mGet({\n ...opts,\n transform: (el: string) => JSON.parse(el),\n });\n }\n\n async mSet<T>(opts: {\n payload: Array<{ key: string; value: T }>;\n options?: { log?: boolean };\n }): Promise<void> {\n const { payload, options } = opts;\n\n if (!payload.length) {\n return;\n }\n\n // A plain loop, not spread-in-reduce: `{ ...current, [key]: v }` copies every key already\n // accumulated on EVERY element, which is O(n^2). Measured at 10k keys: 2.2s of blocked event\n // loop, against 1.5ms for this.\n const serialized: Record<string, string> = {};\n\n for (const { key, value } of payload) {\n serialized[key] = JSON.stringify(value);\n }\n\n await this.client.mset(serialized);\n\n if (!options?.log) {\n return;\n }\n\n this.logger.for(this.mSet.name).info('Payload: %j', serialized);\n }\n\n async mGet<T = string>(opts: {\n keys: Array<string>;\n transform?: (input: string) => T;\n }): Promise<(T | null)[]> {\n const { keys, transform } = opts;\n\n if (!keys.length) {\n return [];\n }\n\n const values = await this.client.mget(keys);\n\n if (!values?.length) {\n return [];\n }\n\n return values.map((el) => (el ? (transform ? transform(el) : (el as T)) : null));\n }\n\n keys(opts: { key: string }): Promise<string[]> {\n const { key } = opts;\n\n return this.client.keys(key);\n }\n\n // --- Hash operations (IRedisHash) ---\n\n async hSet<T extends Record<string, unknown>>(opts: {\n key: string;\n value: T;\n options?: { log?: boolean };\n }): Promise<number> {\n const { key, value, options } = opts;\n const result = await this.client.hset(key, value as Record<string, string | number | Buffer>);\n\n if (!options?.log) {\n return result;\n }\n\n this.logger.for(this.hSet.name).info('Result: %j', result);\n\n return result;\n }\n\n async hGetAll(opts: { key: string; transform?: <T, R>(input: T) => R }) {\n const { key, transform } = opts;\n const value = await this.client.hgetall(key);\n\n if (!transform || !value) {\n return value;\n }\n\n return transform(value);\n }\n\n hGet(opts: { key: string; field: string }): Promise<string | null> {\n const { key, field } = opts;\n\n return this.client.hget(key, field);\n }\n\n hDel(opts: { key: string; fields: Array<string> }): Promise<number> {\n const { key, fields } = opts;\n\n if (!fields.length) {\n return Promise.resolve(0);\n }\n\n return this.client.hdel(key, ...fields);\n }\n\n async hExists(opts: { key: string; field: string }): Promise<boolean> {\n const { key, field } = opts;\n const result = await this.client.hexists(key, field);\n\n return result === 1;\n }\n\n hKeys(opts: { key: string }): Promise<string[]> {\n const { key } = opts;\n\n return this.client.hkeys(key);\n }\n\n hVals(opts: { key: string }): Promise<string[]> {\n const { key } = opts;\n\n return this.client.hvals(key);\n }\n\n hIncrBy(opts: { key: string; field: string; value: number }): Promise<number> {\n const { key, field, value } = opts;\n\n return this.client.hincrby(key, field, value);\n }\n\n hLen(opts: { key: string }): Promise<number> {\n const { key } = opts;\n\n return this.client.hlen(key);\n }\n\n // --- Set operations (IRedisSet) ---\n\n sAdd(opts: { key: string; members: Array<string | number> }): Promise<number> {\n const { key, members } = opts;\n\n if (!members.length) {\n return Promise.resolve(0);\n }\n\n return this.client.sadd(key, ...members);\n }\n\n sRem(opts: { key: string; members: Array<string | number> }): Promise<number> {\n const { key, members } = opts;\n\n if (!members.length) {\n return Promise.resolve(0);\n }\n\n return this.client.srem(key, ...members);\n }\n\n sMembers(opts: { key: string }): Promise<string[]> {\n const { key } = opts;\n\n return this.client.smembers(key);\n }\n\n async sIsMember(opts: { key: string; member: string | number }): Promise<boolean> {\n const { key, member } = opts;\n const result = await this.client.sismember(key, member);\n\n return result === 1;\n }\n\n sCard(opts: { key: string }): Promise<number> {\n const { key } = opts;\n\n return this.client.scard(key);\n }\n\n // --- List operations (IRedisList) ---\n\n lPush(opts: { key: string; values: Array<string | number> }): Promise<number> {\n const { key, values } = opts;\n\n if (!values.length) {\n return Promise.resolve(0);\n }\n\n return this.client.lpush(key, ...values);\n }\n\n rPush(opts: { key: string; values: Array<string | number> }): Promise<number> {\n const { key, values } = opts;\n\n if (!values.length) {\n return Promise.resolve(0);\n }\n\n return this.client.rpush(key, ...values);\n }\n\n lPop(opts: { key: string }): Promise<string | null> {\n const { key } = opts;\n\n return this.client.lpop(key);\n }\n\n rPop(opts: { key: string }): Promise<string | null> {\n const { key } = opts;\n\n return this.client.rpop(key);\n }\n\n lRange(opts: { key: string; start: number; stop: number }): Promise<string[]> {\n const { key, start, stop } = opts;\n\n return this.client.lrange(key, start, stop);\n }\n\n lLen(opts: { key: string }): Promise<number> {\n const { key } = opts;\n\n return this.client.llen(key);\n }\n\n // --- RedisJSON (IRedisJson) ---\n\n jSet<T>(opts: { key: string; path: string; value: T }): Promise<string | null> {\n const { key, path, value } = opts;\n\n return this.execute<string | null>('JSON.SET', [key, path, JSON.stringify(value)]);\n }\n\n jGet<T>(opts: { key: string; path?: string }): Promise<T | null> {\n const { key, path = '$' } = opts;\n\n return this.execute<T | null>('JSON.GET', [key, path]);\n }\n\n jDelete(opts: { key: string; path?: string }): Promise<number> {\n const { key, path = '$' } = opts;\n\n return this.execute<number>('JSON.DEL', [key, path]);\n }\n\n jNumberIncreaseBy(opts: { key: string; path: string; value: number }): Promise<string | null> {\n const { key, path, value } = opts;\n\n return this.execute<string | null>('JSON.NUMINCRBY', [key, path, value]);\n }\n\n jStringAppend(opts: { key: string; path: string; value: string }): Promise<number[] | null> {\n const { key, path, value } = opts;\n\n return this.execute<number[] | null>('JSON.STRAPPEND', [key, path, value]);\n }\n\n jPush<T>(opts: { key: string; path: string; value: T }): Promise<number[] | null> {\n const { key, path, value } = opts;\n\n return this.execute<number[] | null>('JSON.ARRAPPEND', [key, path, JSON.stringify(value)]);\n }\n\n jPop<T>(opts: { key: string; path: string }): Promise<T | null> {\n const { key, path } = opts;\n\n return this.execute<T | null>('JSON.ARRPOP', [key, path]);\n }\n\n // --- Raw command (IRedisCommand) ---\n\n execute<R>(command: string, parameters?: Array<string | number | Buffer>): Promise<R> {\n if (!parameters?.length) {\n return this.client.call(command) as Promise<R>;\n }\n\n return this.client.call(command, parameters) as Promise<R>;\n }\n\n // --- Pub/Sub (IRedisPubSub) ---\n\n async publish<T>(opts: {\n topics: Array<string>;\n payload: T;\n useCompress?: boolean;\n }): Promise<void> {\n const logger = this.logger.for(this.publish.name);\n const { topics, payload, useCompress = false } = opts;\n\n const validTopics = topics?.filter((topic) => !ObjectUtility.isEmpty({ value: topic }));\n\n if (!validTopics?.length) {\n logger.error('No topic(s) to publish!');\n\n return;\n }\n\n if (!payload) {\n logger.error('Invalid payload to publish!');\n\n return;\n }\n\n const message = Buffer.from(JSON.stringify(payload));\n const packet = useCompress ? zlib.deflateSync(message) : message;\n\n // `topics` is caller-supplied, so an unbounded fan-out here is a caller-sized burst on one connection.\n await PromiseUtility.executeWithLimit({\n limit: RedisConcurrency.PUBLISH_LIMIT,\n tasks: validTopics.map((topic) => () => this.client.publish(topic, packet)),\n });\n }\n\n subscribe(opts: { topic: string }) {\n const logger = this.logger.for(this.subscribe.name);\n const { topic } = opts;\n\n if (!topic || ObjectUtility.isEmpty({ value: topic })) {\n logger.error('No topic to subscribe!');\n\n return;\n }\n\n PromiseUtility.voidExecution({\n logger: this.logger,\n scope: this.subscribe.name,\n execution: this.client.subscribe(topic, (error, count) => {\n if (error) {\n logger.error('Failed to subscribe to topic: %s | Error: %s', topic, error);\n\n return;\n }\n\n logger.info('Subscribed to %s channel(s). Listening to channel: %s', count, topic);\n }),\n });\n }\n\n unsubscribe(opts: { topic: string }) {\n const logger = this.logger.for(this.unsubscribe.name);\n const { topic } = opts;\n\n if (!topic || ObjectUtility.isEmpty({ value: topic })) {\n logger.error('No topic to unsubscribe!');\n\n return;\n }\n\n PromiseUtility.voidExecution({\n logger: this.logger,\n scope: this.unsubscribe.name,\n execution: this.client.unsubscribe(topic, (error, count) => {\n if (error) {\n logger.error('Failed to unsubscribe from topic: %s | Error: %s', topic, error);\n\n return;\n }\n\n logger.info('Unsubscribed from %s channel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,CAAC,CAAC;YACrF,CAAC,CAAC;SACH,CAAC,CAAC;IACL,CAAC;IAED,WAAW,CAAC,IAAuB;QACjC,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QACtD,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;QAEvB,IAAI,CAAC,KAAK,IAAI,aAAa,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;YACtD,MAAM,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAC;YAEzC,OAAO;QACT,CAAC;QAED,cAAc,CAAC,aAAa,CAAC;YAC3B,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,KAAK,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI;YAC5B,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;gBACzD,IAAI,KAAK,EAAE,CAAC;oBACV,MAAM,CAAC,KAAK,CAAC,kDAAkD,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;oBAE/E,OAAO;gBACT,CAAC;gBAED,MAAM,CAAC,IAAI,CAAC,kCAAkC,EAAE,KAAK,CAAC,CAAC;YACzD,CAAC,CAAC;SACH,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { ObjectUtility } from '@venizia/ignis-inversion';\nimport { PromiseUtility } from '@/utilities/promise.utility';\nimport { getError } from '@/modules/error';\nimport { LoggerFactory } from '@/modules/logger';\nimport { RetryHelper } from '@/modules/retry';\nimport { BaseHelper } from '@/modules/base';\nimport { type EventEmitter } from 'node:events';\nimport zlib from 'node:zlib';\nimport { RedisConcurrency, RedisDefaults } from './../common/constants';\nimport { type IRedisHelper } from './../common/interfaces';\nimport { type IRedisHelperCallbacks, type TRedisClient } from './../common/types';\n\n/** Registry symbol that marks an instance as a Redis helper; `isRedisHelper` tests for it. */\nexport const REDIS_HELPER_BRAND = Symbol.for('@venizia/ignis-helpers:abstract-redis-helper');\n\n/** Brand check, never `instanceof`: two installed copies of this package are two distinct classes, so a helper built by one is rejected by the other. `Symbol.for` is realm-keyed and survives that. */\nexport const isRedisHelper = (value: unknown): value is AbstractRedisHelper => {\n return typeof value === 'object' && value !== null && REDIS_HELPER_BRAND in value;\n};\n\n/** Base for the Redis helpers: wraps one ioredis client, logs its lifecycle events and forwards them to the `onInitialized`, `onConnected`, `onReady` and `onError` callbacks. Subclasses build the client. */\nexport class AbstractRedisHelper<ClientType extends TRedisClient = TRedisClient>\n extends BaseHelper\n implements IRedisHelper\n{\n /** Read by {@link isRedisHelper}. On the instance, so every subclass instance carries it. */\n readonly [REDIS_HELPER_BRAND] = true;\n\n client: ClientType;\n readonly name: string;\n\n constructor(\n opts: { scope: string; identifier: string; client: ClientType } & IRedisHelperCallbacks,\n ) {\n super({ scope: opts.scope, identifier: opts.identifier });\n\n this.name = opts.identifier;\n this.client = opts.client;\n\n const { onInitialized, onConnected, onReady, onError } = opts;\n const emitter = this.client as EventEmitter;\n\n emitter.on('connect', () => {\n this.logger.for('connect').info('Redis CONNECTED | Name: %s', this.name);\n onConnected?.({ name: this.name, helper: this });\n });\n\n emitter.on('ready', () => {\n this.logger.for('ready').info('Redis READY | Name: %s', this.name);\n onReady?.({ name: this.name, helper: this });\n });\n\n emitter.on('error', (error: Error) => {\n this.logger.for('error').error('Redis ERROR | Name: %s | Error: %s', this.name, error);\n onError?.({ name: this.name, helper: this, error });\n });\n\n emitter.on('reconnecting', () => {\n this.logger.for('reconnecting').warn('Redis client RECONNECTING | Name: %s', this.name);\n });\n\n onInitialized?.({ name: this.name, helper: this });\n }\n\n /** `maxRetry` is `0`, `RedisDefaults.RETRY_FOREVER` or a positive integer; anything else is a typo that would silently change how the client reconnects. */\n protected static assertMaxRetry(opts: { scope: string; name: string; maxRetry: number }) {\n const { scope, name, maxRetry } = opts;\n\n if (!Number.isInteger(maxRetry) || (maxRetry < 0 && maxRetry !== RedisDefaults.RETRY_FOREVER)) {\n throw getError({\n message: `[${scope}] maxRetry must be 0, ${RedisDefaults.RETRY_FOREVER} (forever) or a positive integer | name: ${name} | value: ${maxRetry}`,\n });\n }\n }\n\n /** The wait before each reconnect, then `undefined` once `maxRetry` attempts failed: ioredis stops and the helper logs it once. */\n protected static buildRetryStrategy(opts: { scope: string; name: string; maxRetry: number }) {\n const { scope, name, maxRetry } = opts;\n\n AbstractRedisHelper.assertMaxRetry(opts);\n\n return (attempt: number) => {\n if (maxRetry !== RedisDefaults.RETRY_FOREVER && attempt > maxRetry) {\n LoggerFactory.getLogger([scope, name])\n .for('retry')\n .error('Redis gave up reconnecting | Name: %s | maxRetry: %d', name, maxRetry);\n\n return undefined;\n }\n\n return RetryHelper.computeBackoffDelayMs({\n attempt,\n backoff: RedisDefaults.RECONNECT_BACKOFF,\n });\n };\n }\n\n protected static buildDefaultOpts(opts: { scope: string; name: string; maxRetry: number }) {\n return {\n showFriendlyErrorStack: true,\n maxRetriesPerRequest: null,\n retryStrategy: AbstractRedisHelper.buildRetryStrategy(opts),\n };\n }\n\n // --- Connection lifecycle (IRedisConnection) ---\n\n getClient() {\n return this.client;\n }\n\n duplicateClient(): TRedisClient {\n // ioredis 6 types `duplicate` per client; the `Redis | Cluster` union has no callable signature.\n const duplicable: { duplicate: () => TRedisClient } = this.client;\n\n return duplicable.duplicate();\n }\n\n ping() {\n return this.client.ping();\n }\n\n async connect() {\n // `connect` is the cluster-only step between `connecting` and `ready`: ioredis refuses a second connect() there as well.\n const invalidStatuses: (typeof this.client.status)[] = [\n 'ready',\n 'reconnecting',\n 'connecting',\n 'connect',\n ];\n\n if (invalidStatuses.includes(this.client.status)) {\n this.logger\n .for(this.connect.name)\n .info('status: %s | Invalid redis status to invoke connect', this.client.status);\n\n return false;\n }\n\n await this.client.connect();\n\n return this.client.status === 'ready';\n }\n\n async disconnect() {\n const invalidStatuses: (typeof this.client.status)[] = ['end', 'close'];\n\n if (invalidStatuses.includes(this.client.status)) {\n this.logger\n .for(this.disconnect.name)\n .info('status: %s | Invalid redis status to invoke disconnect', this.client.status);\n\n return false;\n }\n\n const reply = await this.client.quit();\n\n return reply === 'OK';\n }\n\n // --- Key lifecycle + counters (IRedisKey) ---\n\n exists(opts: { keys: Array<string> }): Promise<number> {\n const { keys } = opts;\n\n if (!keys.length) {\n return Promise.resolve(0);\n }\n\n return this.client.exists(...keys);\n }\n\n async expire(opts: { key: string; seconds: number }): Promise<boolean> {\n const { key, seconds } = opts;\n const result = await this.client.expire(key, seconds);\n\n return result === 1;\n }\n\n async expireAt(opts: { key: string; atEpochSeconds: number }): Promise<boolean> {\n const { key, atEpochSeconds } = opts;\n const result = await this.client.expireat(key, atEpochSeconds);\n\n return result === 1;\n }\n\n ttl(opts: { key: string }): Promise<number> {\n const { key } = opts;\n\n return this.client.ttl(key);\n }\n\n async persist(opts: { key: string }): Promise<boolean> {\n const { key } = opts;\n const result = await this.client.persist(key);\n\n return result === 1;\n }\n\n incr(opts: { key: string }): Promise<number> {\n const { key } = opts;\n\n return this.client.incr(key);\n }\n\n decr(opts: { key: string }): Promise<number> {\n const { key } = opts;\n\n return this.client.decr(key);\n }\n\n incrBy(opts: { key: string; value: number }): Promise<number> {\n const { key, value } = opts;\n\n return this.client.incrby(key, value);\n }\n\n decrBy(opts: { key: string; value: number }): Promise<number> {\n const { key, value } = opts;\n\n return this.client.decrby(key, value);\n }\n\n // --- Key-value (IRedisKeyValue) ---\n\n async set<T>(opts: {\n key: string;\n value: T;\n options?: { log?: boolean; expiresIn?: number };\n }): Promise<void> {\n const { key, value, options } = opts;\n\n const serialized = JSON.stringify(value);\n\n if (typeof options?.expiresIn === 'number' && options.expiresIn > 0) {\n await this.client.set(key, serialized, 'PX', options.expiresIn);\n } else {\n await this.client.set(key, serialized);\n }\n\n if (!options?.log) {\n return;\n }\n\n this.logger.for(this.set.name).info('Set key: %s | value: %s', key, serialized);\n }\n\n async get<T = string>(opts: {\n key: string;\n transform?: (input: string) => T;\n }): Promise<T | null> {\n const { key, transform } = opts;\n\n const value = await this.client.get(key);\n\n if (!value) {\n return null;\n }\n\n return transform ? transform(value) : (value as T);\n }\n\n del(opts: { keys: Array<string> }): Promise<number> {\n const { keys } = opts;\n\n if (!keys.length) {\n return Promise.resolve(0);\n }\n\n return this.client.del(keys);\n }\n\n getString(opts: { key: string }) {\n return this.get(opts);\n }\n\n getStrings(opts: { keys: Array<string> }) {\n return this.mGet(opts);\n }\n\n getObject<T>(opts: { key: string }) {\n return this.get<T>({\n ...opts,\n transform: (el: string) => JSON.parse(el),\n });\n }\n\n getObjects(opts: { keys: Array<string> }) {\n return this.mGet({\n ...opts,\n transform: (el: string) => JSON.parse(el),\n });\n }\n\n async mSet<T>(opts: {\n payload: Array<{ key: string; value: T }>;\n options?: { log?: boolean };\n }): Promise<void> {\n const { payload, options } = opts;\n\n if (!payload.length) {\n return;\n }\n\n // A plain loop, not spread-in-reduce: `{ ...current, [key]: v }` copies every key already\n // accumulated on EVERY element, which is O(n^2). Measured at 10k keys: 2.2s of blocked event\n // loop, against 1.5ms for this.\n const serialized: Record<string, string> = {};\n\n for (const { key, value } of payload) {\n serialized[key] = JSON.stringify(value);\n }\n\n await this.client.mset(serialized);\n\n if (!options?.log) {\n return;\n }\n\n this.logger.for(this.mSet.name).info('Payload: %j', serialized);\n }\n\n async mGet<T = string>(opts: {\n keys: Array<string>;\n transform?: (input: string) => T;\n }): Promise<(T | null)[]> {\n const { keys, transform } = opts;\n\n if (!keys.length) {\n return [];\n }\n\n const values = await this.client.mget(keys);\n\n if (!values?.length) {\n return [];\n }\n\n return values.map((el) => (el ? (transform ? transform(el) : (el as T)) : null));\n }\n\n keys(opts: { key: string }): Promise<string[]> {\n const { key } = opts;\n\n return this.client.keys(key);\n }\n\n // --- Hash operations (IRedisHash) ---\n\n async hSet<T extends Record<string, unknown>>(opts: {\n key: string;\n value: T;\n options?: { log?: boolean };\n }): Promise<number> {\n const { key, value, options } = opts;\n const result = await this.client.hset(key, value as Record<string, string | number | Buffer>);\n\n if (!options?.log) {\n return result;\n }\n\n this.logger.for(this.hSet.name).info('Result: %j', result);\n\n return result;\n }\n\n async hGetAll(opts: { key: string; transform?: <T, R>(input: T) => R }) {\n const { key, transform } = opts;\n const value = await this.client.hgetall(key);\n\n if (!transform || !value) {\n return value;\n }\n\n return transform(value);\n }\n\n hGet(opts: { key: string; field: string }): Promise<string | null> {\n const { key, field } = opts;\n\n return this.client.hget(key, field);\n }\n\n hDel(opts: { key: string; fields: Array<string> }): Promise<number> {\n const { key, fields } = opts;\n\n if (!fields.length) {\n return Promise.resolve(0);\n }\n\n return this.client.hdel(key, ...fields);\n }\n\n async hExists(opts: { key: string; field: string }): Promise<boolean> {\n const { key, field } = opts;\n const result = await this.client.hexists(key, field);\n\n return result === 1;\n }\n\n hKeys(opts: { key: string }): Promise<string[]> {\n const { key } = opts;\n\n return this.client.hkeys(key);\n }\n\n hVals(opts: { key: string }): Promise<string[]> {\n const { key } = opts;\n\n return this.client.hvals(key);\n }\n\n hIncrBy(opts: { key: string; field: string; value: number }): Promise<number> {\n const { key, field, value } = opts;\n\n return this.client.hincrby(key, field, value);\n }\n\n hLen(opts: { key: string }): Promise<number> {\n const { key } = opts;\n\n return this.client.hlen(key);\n }\n\n // --- Set operations (IRedisSet) ---\n\n sAdd(opts: { key: string; members: Array<string | number> }): Promise<number> {\n const { key, members } = opts;\n\n if (!members.length) {\n return Promise.resolve(0);\n }\n\n return this.client.sadd(key, ...members);\n }\n\n sRem(opts: { key: string; members: Array<string | number> }): Promise<number> {\n const { key, members } = opts;\n\n if (!members.length) {\n return Promise.resolve(0);\n }\n\n return this.client.srem(key, ...members);\n }\n\n sMembers(opts: { key: string }): Promise<string[]> {\n const { key } = opts;\n\n return this.client.smembers(key);\n }\n\n async sIsMember(opts: { key: string; member: string | number }): Promise<boolean> {\n const { key, member } = opts;\n const result = await this.client.sismember(key, member);\n\n return result === 1;\n }\n\n sCard(opts: { key: string }): Promise<number> {\n const { key } = opts;\n\n return this.client.scard(key);\n }\n\n // --- List operations (IRedisList) ---\n\n lPush(opts: { key: string; values: Array<string | number> }): Promise<number> {\n const { key, values } = opts;\n\n if (!values.length) {\n return Promise.resolve(0);\n }\n\n return this.client.lpush(key, ...values);\n }\n\n rPush(opts: { key: string; values: Array<string | number> }): Promise<number> {\n const { key, values } = opts;\n\n if (!values.length) {\n return Promise.resolve(0);\n }\n\n return this.client.rpush(key, ...values);\n }\n\n lPop(opts: { key: string }): Promise<string | null> {\n const { key } = opts;\n\n return this.client.lpop(key);\n }\n\n rPop(opts: { key: string }): Promise<string | null> {\n const { key } = opts;\n\n return this.client.rpop(key);\n }\n\n lRange(opts: { key: string; start: number; stop: number }): Promise<string[]> {\n const { key, start, stop } = opts;\n\n return this.client.lrange(key, start, stop);\n }\n\n lLen(opts: { key: string }): Promise<number> {\n const { key } = opts;\n\n return this.client.llen(key);\n }\n\n // --- RedisJSON (IRedisJson) ---\n\n jSet<T>(opts: { key: string; path: string; value: T }): Promise<string | null> {\n const { key, path, value } = opts;\n\n return this.execute<string | null>('JSON.SET', [key, path, JSON.stringify(value)]);\n }\n\n jGet<T>(opts: { key: string; path?: string }): Promise<T | null> {\n const { key, path = '$' } = opts;\n\n return this.execute<T | null>('JSON.GET', [key, path]);\n }\n\n jDelete(opts: { key: string; path?: string }): Promise<number> {\n const { key, path = '$' } = opts;\n\n return this.execute<number>('JSON.DEL', [key, path]);\n }\n\n jNumberIncreaseBy(opts: { key: string; path: string; value: number }): Promise<string | null> {\n const { key, path, value } = opts;\n\n return this.execute<string | null>('JSON.NUMINCRBY', [key, path, value]);\n }\n\n jStringAppend(opts: { key: string; path: string; value: string }): Promise<number[] | null> {\n const { key, path, value } = opts;\n\n return this.execute<number[] | null>('JSON.STRAPPEND', [key, path, value]);\n }\n\n jPush<T>(opts: { key: string; path: string; value: T }): Promise<number[] | null> {\n const { key, path, value } = opts;\n\n return this.execute<number[] | null>('JSON.ARRAPPEND', [key, path, JSON.stringify(value)]);\n }\n\n jPop<T>(opts: { key: string; path: string }): Promise<T | null> {\n const { key, path } = opts;\n\n return this.execute<T | null>('JSON.ARRPOP', [key, path]);\n }\n\n // --- Raw command (IRedisCommand) ---\n\n execute<R>(command: string, parameters?: Array<string | number | Buffer>): Promise<R> {\n if (!parameters?.length) {\n return this.client.call(command) as Promise<R>;\n }\n\n return this.client.call(command, parameters) as Promise<R>;\n }\n\n // --- Pub/Sub (IRedisPubSub) ---\n\n async publish<T>(opts: {\n topics: Array<string>;\n payload: T;\n useCompress?: boolean;\n }): Promise<void> {\n const logger = this.logger.for(this.publish.name);\n const { topics, payload, useCompress = false } = opts;\n\n const validTopics = topics?.filter((topic) => !ObjectUtility.isEmpty({ value: topic }));\n\n if (!validTopics?.length) {\n logger.error('No topic(s) to publish!');\n\n return;\n }\n\n if (!payload) {\n logger.error('Invalid payload to publish!');\n\n return;\n }\n\n const message = Buffer.from(JSON.stringify(payload));\n const packet = useCompress ? zlib.deflateSync(message) : message;\n\n // `topics` is caller-supplied, so an unbounded fan-out here is a caller-sized burst on one connection.\n await PromiseUtility.executeWithLimit({\n limit: RedisConcurrency.PUBLISH_LIMIT,\n tasks: validTopics.map((topic) => () => this.client.publish(topic, packet)),\n });\n }\n\n subscribe(opts: { topic: string }) {\n const logger = this.logger.for(this.subscribe.name);\n const { topic } = opts;\n\n if (!topic || ObjectUtility.isEmpty({ value: topic })) {\n logger.error('No topic to subscribe!');\n\n return;\n }\n\n PromiseUtility.voidExecution({\n logger: this.logger,\n scope: this.subscribe.name,\n execution: this.client.subscribe(topic, (error, count) => {\n if (error) {\n logger.error('Failed to subscribe to topic: %s | Error: %s', topic, error);\n\n return;\n }\n\n logger.info('Subscribed to %s channel(s). Listening to channel: %s', count, topic);\n }),\n });\n }\n\n unsubscribe(opts: { topic: string }) {\n const logger = this.logger.for(this.unsubscribe.name);\n const { topic } = opts;\n\n if (!topic || ObjectUtility.isEmpty({ value: topic })) {\n logger.error('No topic to unsubscribe!');\n\n return;\n }\n\n PromiseUtility.voidExecution({\n logger: this.logger,\n scope: this.unsubscribe.name,\n execution: this.client.unsubscribe(topic, (error, count) => {\n if (error) {\n logger.error('Failed to unsubscribe from topic: %s | Error: %s', topic, error);\n\n return;\n }\n\n logger.info('Unsubscribed from %s channel(s).', count);\n }),\n });\n }\n}\n"]}
|
|
@@ -8,6 +8,8 @@ export interface IRedisSingleHelperProps {
|
|
|
8
8
|
name: string;
|
|
9
9
|
host: string;
|
|
10
10
|
port: string | number;
|
|
11
|
+
/** The Redis ACL user to authenticate as, with `password`. Omit it to authenticate as the `default` user. */
|
|
12
|
+
username?: string;
|
|
11
13
|
/** Omit it for a Redis with no password. */
|
|
12
14
|
password?: string;
|
|
13
15
|
/** @default 0 */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/modules/redis/common/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Cluster, ClusterOptions, Redis, RedisOptions } from 'ioredis';\nimport type { TRedisSentinelRole } from './constants';\nimport type { IRedisHelper } from './interfaces';\n\n/** The ioredis client a helper wraps: a single or Sentinel `Redis`, or a `Cluster`. */\nexport type TRedisClient = Redis | Cluster;\n\n/** Connection settings for a single Redis node. */\nexport interface IRedisSingleHelperProps {\n name: string;\n host: string;\n port: string | number;\n /** Omit it for a Redis with no password. */\n password?: string;\n /** @default 0 */\n database?: number;\n /** @default true */\n autoConnect?: boolean;\n /** Reconnect attempts: `0` never reconnects, `-1` never gives up; any other value is refused. @default RedisDefaults.MAX_RETRY (5) */\n maxRetry?: number;\n}\n\n/** Connection settings for a Redis Cluster: the startup `nodes`, plus raw ioredis `clusterOptions` that override the helper defaults. */\nexport interface IRedisClusterHelperProps {\n name: string;\n nodes: Array<{ host: string; port: string | number; password?: string }>;\n /**\n * Same meaning as on single and sentinel: `false` holds the client open for a later `connect()`.\n *\n * @default true\n */\n autoConnect?: boolean;\n /** Reconnect attempts: `0` never reconnects, `-1` never gives up; any other value is refused. `clusterOptions` still overrides. @default RedisDefaults.MAX_RETRY (5) */\n maxRetry?: number;\n clusterOptions?: ClusterOptions;\n}\n\n/** Connection settings for Redis behind Sentinel. `redisOptions` overrides the helper defaults. */\nexport interface IRedisSentinelHelperProps {\n name: string;\n sentinels: Array<{\n host: string;\n /** @default 26379 */\n port?: string | number;\n }>;\n masterName: string;\n /** @default RedisSentinelRoles.MASTER */\n role?: TRedisSentinelRole;\n password?: string;\n sentinelPassword?: string;\n sentinelUsername?: string;\n /** @default 0 */\n database?: number;\n /** @default true */\n autoConnect?: boolean;\n /** Reconnect attempts: `0` never reconnects, `-1` never gives up; any other value is refused. @default RedisDefaults.MAX_RETRY (5) */\n maxRetry?: number;\n redisOptions?: Partial<RedisOptions>;\n}\n\n/** Lifecycle hooks a Redis helper calls; each receives the helper name and the helper itself. */\nexport interface IRedisHelperCallbacks {\n onInitialized?: (opts: { name: string; helper: IRedisHelper }) => void;\n onConnected?: (opts: { name: string; helper: IRedisHelper }) => void;\n onReady?: (opts: { name: string; helper: IRedisHelper }) => void;\n onError?: (opts: { name: string; helper: IRedisHelper; error: unknown }) => void;\n}\n\n/**\n * `ioredis` is an optional peer, loaded when a client is built. A `bun build --compile` binary\n * carries no `node_modules` to load it from: pass the module here, or register it once with\n * `ModuleUtility.register({ modules: { ioredis } })` at the entry.\n */\nexport interface IRedisModuleOption {\n module?: typeof import('ioredis');\n}\n\n/** Options for `RedisSingleHelper`: connection props, lifecycle callbacks and an optional `ioredis` module. */\nexport interface IRedisSingleHelperOptions\n extends IRedisSingleHelperProps, IRedisHelperCallbacks, IRedisModuleOption {}\n\n/** Options for `RedisClusterHelper`: connection props, lifecycle callbacks and an optional `ioredis` module. */\nexport interface IRedisClusterHelperOptions\n extends IRedisClusterHelperProps, IRedisHelperCallbacks, IRedisModuleOption {}\n\n/** Options for `RedisSentinelHelper`: connection props, lifecycle callbacks and an optional `ioredis` module. */\nexport interface IRedisSentinelHelperOptions\n extends IRedisSentinelHelperProps, IRedisHelperCallbacks, IRedisModuleOption {}\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/modules/redis/common/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Cluster, ClusterOptions, Redis, RedisOptions } from 'ioredis';\nimport type { TRedisSentinelRole } from './constants';\nimport type { IRedisHelper } from './interfaces';\n\n/** The ioredis client a helper wraps: a single or Sentinel `Redis`, or a `Cluster`. */\nexport type TRedisClient = Redis | Cluster;\n\n/** Connection settings for a single Redis node. */\nexport interface IRedisSingleHelperProps {\n name: string;\n host: string;\n port: string | number;\n /** The Redis ACL user to authenticate as, with `password`. Omit it to authenticate as the `default` user. */\n username?: string;\n /** Omit it for a Redis with no password. */\n password?: string;\n /** @default 0 */\n database?: number;\n /** @default true */\n autoConnect?: boolean;\n /** Reconnect attempts: `0` never reconnects, `-1` never gives up; any other value is refused. @default RedisDefaults.MAX_RETRY (5) */\n maxRetry?: number;\n}\n\n/** Connection settings for a Redis Cluster: the startup `nodes`, plus raw ioredis `clusterOptions` that override the helper defaults. */\nexport interface IRedisClusterHelperProps {\n name: string;\n nodes: Array<{ host: string; port: string | number; password?: string }>;\n /**\n * Same meaning as on single and sentinel: `false` holds the client open for a later `connect()`.\n *\n * @default true\n */\n autoConnect?: boolean;\n /** Reconnect attempts: `0` never reconnects, `-1` never gives up; any other value is refused. `clusterOptions` still overrides. @default RedisDefaults.MAX_RETRY (5) */\n maxRetry?: number;\n clusterOptions?: ClusterOptions;\n}\n\n/** Connection settings for Redis behind Sentinel. `redisOptions` overrides the helper defaults. */\nexport interface IRedisSentinelHelperProps {\n name: string;\n sentinels: Array<{\n host: string;\n /** @default 26379 */\n port?: string | number;\n }>;\n masterName: string;\n /** @default RedisSentinelRoles.MASTER */\n role?: TRedisSentinelRole;\n password?: string;\n sentinelPassword?: string;\n sentinelUsername?: string;\n /** @default 0 */\n database?: number;\n /** @default true */\n autoConnect?: boolean;\n /** Reconnect attempts: `0` never reconnects, `-1` never gives up; any other value is refused. @default RedisDefaults.MAX_RETRY (5) */\n maxRetry?: number;\n redisOptions?: Partial<RedisOptions>;\n}\n\n/** Lifecycle hooks a Redis helper calls; each receives the helper name and the helper itself. */\nexport interface IRedisHelperCallbacks {\n onInitialized?: (opts: { name: string; helper: IRedisHelper }) => void;\n onConnected?: (opts: { name: string; helper: IRedisHelper }) => void;\n onReady?: (opts: { name: string; helper: IRedisHelper }) => void;\n onError?: (opts: { name: string; helper: IRedisHelper; error: unknown }) => void;\n}\n\n/**\n * `ioredis` is an optional peer, loaded when a client is built. A `bun build --compile` binary\n * carries no `node_modules` to load it from: pass the module here, or register it once with\n * `ModuleUtility.register({ modules: { ioredis } })` at the entry.\n */\nexport interface IRedisModuleOption {\n module?: typeof import('ioredis');\n}\n\n/** Options for `RedisSingleHelper`: connection props, lifecycle callbacks and an optional `ioredis` module. */\nexport interface IRedisSingleHelperOptions\n extends IRedisSingleHelperProps, IRedisHelperCallbacks, IRedisModuleOption {}\n\n/** Options for `RedisClusterHelper`: connection props, lifecycle callbacks and an optional `ioredis` module. */\nexport interface IRedisClusterHelperOptions\n extends IRedisClusterHelperProps, IRedisHelperCallbacks, IRedisModuleOption {}\n\n/** Options for `RedisSentinelHelper`: connection props, lifecycle callbacks and an optional `ioredis` module. */\nexport interface IRedisSentinelHelperOptions\n extends IRedisSentinelHelperProps, IRedisHelperCallbacks, IRedisModuleOption {}\n"]}
|
|
@@ -5,7 +5,7 @@ import { RedisDefaults } from './../common/index.js';
|
|
|
5
5
|
/** Redis helper over one ioredis `Redis` client connected to a single node. */
|
|
6
6
|
export class RedisSingleHelper extends AbstractRedisHelper {
|
|
7
7
|
constructor(opts) {
|
|
8
|
-
const { name, host, port, password, database = 0, autoConnect = true, maxRetry = RedisDefaults.MAX_RETRY, } = opts;
|
|
8
|
+
const { name, host, port, username, password, database = 0, autoConnect = true, maxRetry = RedisDefaults.MAX_RETRY, } = opts;
|
|
9
9
|
// Optional peer, loaded when a client is built: an app with no Redis installs no ioredis.
|
|
10
10
|
const ioredis = opts.module ?? ModuleUtility.loadSync({ module: 'ioredis' });
|
|
11
11
|
super({
|
|
@@ -16,6 +16,7 @@ export class RedisSingleHelper extends AbstractRedisHelper {
|
|
|
16
16
|
name,
|
|
17
17
|
host,
|
|
18
18
|
port: ParseUtility.toInt({ input: port }),
|
|
19
|
+
username,
|
|
19
20
|
password,
|
|
20
21
|
db: database,
|
|
21
22
|
lazyConnect: !autoConnect,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"single.helper.js","sourceRoot":"","sources":["../../../../../src/modules/redis/single/single.helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,aAAa,EAAkC,MAAM,aAAa,CAAC;AAE5E,+EAA+E;AAC/E,MAAM,OAAO,iBAAkB,SAAQ,mBAA0B;IAC/D,YAAY,IAA+B;QACzC,MAAM,EACJ,IAAI,EACJ,IAAI,EACJ,IAAI,EACJ,QAAQ,EACR,QAAQ,GAAG,CAAC,EACZ,WAAW,GAAG,IAAI,EAClB,QAAQ,GAAG,aAAa,CAAC,SAAS,GACnC,GAAG,IAAI,CAAC;QAET,0FAA0F;QAC1F,MAAM,OAAO,GACX,IAAI,CAAC,MAAM,IAAI,aAAa,CAAC,QAAQ,CAA2B,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;QAEzF,KAAK,CAAC;YACJ,GAAG,IAAI;YACP,KAAK,EAAE,iBAAiB,CAAC,IAAI;YAC7B,UAAU,EAAE,IAAI;YAChB,MAAM,EAAE,IAAI,OAAO,CAAC,KAAK,CAAC;gBACxB,IAAI;gBACJ,IAAI;gBACJ,IAAI,EAAE,YAAY,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;gBACzC,QAAQ;gBACR,EAAE,EAAE,QAAQ;gBACZ,WAAW,EAAE,CAAC,WAAW;gBACzB,GAAG,mBAAmB,CAAC,gBAAgB,CAAC,EAAE,KAAK,EAAE,iBAAiB,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;aAC3F,CAAC;SACH,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { ModuleUtility } from '@/utilities/module.utility';\nimport { ParseUtility } from '@/utilities/parse.utility';\nimport type { Redis } from 'ioredis';\nimport { AbstractRedisHelper } from './../base';\nimport { RedisDefaults, type IRedisSingleHelperOptions } from './../common';\n\n/** Redis helper over one ioredis `Redis` client connected to a single node. */\nexport class RedisSingleHelper extends AbstractRedisHelper<Redis> {\n constructor(opts: IRedisSingleHelperOptions) {\n const {\n name,\n host,\n port,\n password,\n database = 0,\n autoConnect = true,\n maxRetry = RedisDefaults.MAX_RETRY,\n } = opts;\n\n // Optional peer, loaded when a client is built: an app with no Redis installs no ioredis.\n const ioredis =\n opts.module ?? ModuleUtility.loadSync<typeof import('ioredis')>({ module: 'ioredis' });\n\n super({\n ...opts,\n scope: RedisSingleHelper.name,\n identifier: name,\n client: new ioredis.Redis({\n name,\n host,\n port: ParseUtility.toInt({ input: port }),\n password,\n db: database,\n lazyConnect: !autoConnect,\n ...AbstractRedisHelper.buildDefaultOpts({ scope: RedisSingleHelper.name, name, maxRetry }),\n }),\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"single.helper.js","sourceRoot":"","sources":["../../../../../src/modules/redis/single/single.helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,aAAa,EAAkC,MAAM,aAAa,CAAC;AAE5E,+EAA+E;AAC/E,MAAM,OAAO,iBAAkB,SAAQ,mBAA0B;IAC/D,YAAY,IAA+B;QACzC,MAAM,EACJ,IAAI,EACJ,IAAI,EACJ,IAAI,EACJ,QAAQ,EACR,QAAQ,EACR,QAAQ,GAAG,CAAC,EACZ,WAAW,GAAG,IAAI,EAClB,QAAQ,GAAG,aAAa,CAAC,SAAS,GACnC,GAAG,IAAI,CAAC;QAET,0FAA0F;QAC1F,MAAM,OAAO,GACX,IAAI,CAAC,MAAM,IAAI,aAAa,CAAC,QAAQ,CAA2B,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;QAEzF,KAAK,CAAC;YACJ,GAAG,IAAI;YACP,KAAK,EAAE,iBAAiB,CAAC,IAAI;YAC7B,UAAU,EAAE,IAAI;YAChB,MAAM,EAAE,IAAI,OAAO,CAAC,KAAK,CAAC;gBACxB,IAAI;gBACJ,IAAI;gBACJ,IAAI,EAAE,YAAY,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;gBACzC,QAAQ;gBACR,QAAQ;gBACR,EAAE,EAAE,QAAQ;gBACZ,WAAW,EAAE,CAAC,WAAW;gBACzB,GAAG,mBAAmB,CAAC,gBAAgB,CAAC,EAAE,KAAK,EAAE,iBAAiB,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;aAC3F,CAAC;SACH,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { ModuleUtility } from '@/utilities/module.utility';\nimport { ParseUtility } from '@/utilities/parse.utility';\nimport type { Redis } from 'ioredis';\nimport { AbstractRedisHelper } from './../base';\nimport { RedisDefaults, type IRedisSingleHelperOptions } from './../common';\n\n/** Redis helper over one ioredis `Redis` client connected to a single node. */\nexport class RedisSingleHelper extends AbstractRedisHelper<Redis> {\n constructor(opts: IRedisSingleHelperOptions) {\n const {\n name,\n host,\n port,\n username,\n password,\n database = 0,\n autoConnect = true,\n maxRetry = RedisDefaults.MAX_RETRY,\n } = opts;\n\n // Optional peer, loaded when a client is built: an app with no Redis installs no ioredis.\n const ioredis =\n opts.module ?? ModuleUtility.loadSync<typeof import('ioredis')>({ module: 'ioredis' });\n\n super({\n ...opts,\n scope: RedisSingleHelper.name,\n identifier: name,\n client: new ioredis.Redis({\n name,\n host,\n port: ParseUtility.toInt({ input: port }),\n username,\n password,\n db: database,\n lazyConnect: !autoConnect,\n ...AbstractRedisHelper.buildDefaultOpts({ scope: RedisSingleHelper.name, name, maxRetry }),\n }),\n });\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@venizia/ignis-helpers",
|
|
3
|
-
"version": "0.4.8-
|
|
3
|
+
"version": "0.4.8-12",
|
|
4
4
|
"description": "Production-ready TypeScript utility library: pluggable logging (winston or pino behind one ILogger contract), Redis single/cluster/sentinel with pub/sub, BullMQ/MQTT/Kafka message queues, MinIO/Disk/Bun-S3 object storage, AES-256/RSA/ECDH cryptography, Snowflake UID generation, cron scheduling, Socket.IO/WebSocket, TCP/TLS/UDP networking, HTTP clients, secrets/Vault, worker thread pools, and environment management. Sub-path imports isolate optional peer dependencies so the root barrel never forces a peer into your bundle.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"aes",
|
|
@@ -176,7 +176,7 @@
|
|
|
176
176
|
"force-update": "sh ../../scripts/build/force-update.sh"
|
|
177
177
|
},
|
|
178
178
|
"dependencies": {
|
|
179
|
-
"@venizia/ignis-inversion": "0.4.7-
|
|
179
|
+
"@venizia/ignis-inversion": "0.4.7-4",
|
|
180
180
|
"reflect-metadata": "^0.2.2",
|
|
181
181
|
"zod": "^4.6.7"
|
|
182
182
|
},
|
|
@@ -188,7 +188,7 @@
|
|
|
188
188
|
"@socket.io/redis-emitter": "^5.1.0",
|
|
189
189
|
"@types/bun": "^1.4.3",
|
|
190
190
|
"@types/luxon": "^3.7.6",
|
|
191
|
-
"@venizia/dev-configs": "0.4.8-
|
|
191
|
+
"@venizia/dev-configs": "0.4.8-9",
|
|
192
192
|
"axios": "^1.20.0",
|
|
193
193
|
"bullmq": "^6.4.0",
|
|
194
194
|
"cron": "^4.4.0",
|