mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-21 20:00:02 +00:00
feat(core): Make Redis available for backend communication (#6719)
* support redis cluster * cleanup, fix config schema * set default prefix to bull * initial commit * improve logging * improve types and refactor * list support and refactor * fix redis service and tests * add comment * add redis and cache prefix * use injection * lint fix * clean schema comments * improve naming, tests, cluster client * merge master * cache returns unknown instead of T * update cache service, tests and doc * remove console.log * do not cache null or undefined values * fix merge * lint fix
This commit is contained in:
committed by
GitHub
parent
4ac4b850dd
commit
3cad60e918
@@ -0,0 +1,46 @@
|
||||
import { Service } from 'typedi';
|
||||
import { LoggerProxy as Logger } from 'n8n-workflow';
|
||||
import {
|
||||
COMMAND_REDIS_CHANNEL,
|
||||
EVENT_BUS_REDIS_CHANNEL,
|
||||
WORKER_RESPONSE_REDIS_CHANNEL,
|
||||
} from './RedisServiceHelper';
|
||||
import { RedisServiceBaseReceiver } from './RedisServiceBaseClasses';
|
||||
|
||||
@Service()
|
||||
export class RedisServicePubSubSubscriber extends RedisServiceBaseReceiver {
|
||||
async init(): Promise<void> {
|
||||
await super.init('subscriber');
|
||||
|
||||
this.redisClient?.on('message', (channel: string, message: string) => {
|
||||
this.messageHandlers.forEach((handler: (channel: string, message: string) => void) =>
|
||||
handler(channel, message),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
async subscribe(channel: string): Promise<void> {
|
||||
if (!this.redisClient) {
|
||||
await this.init();
|
||||
}
|
||||
await this.redisClient?.subscribe(channel, (error, count: number) => {
|
||||
if (error) {
|
||||
Logger.error(`Error subscribing to channel ${channel}`);
|
||||
} else {
|
||||
Logger.debug(`Subscribed ${count.toString()} to eventlog channel`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async subscribeToEventLog(): Promise<void> {
|
||||
await this.subscribe(EVENT_BUS_REDIS_CHANNEL);
|
||||
}
|
||||
|
||||
async subscribeToCommandChannel(): Promise<void> {
|
||||
await this.subscribe(COMMAND_REDIS_CHANNEL);
|
||||
}
|
||||
|
||||
async subscribeToWorkerResponseChannel(): Promise<void> {
|
||||
await this.subscribe(WORKER_RESPONSE_REDIS_CHANNEL);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user