Skip to content

Commit

Permalink
feat(redis): add compatibility to redis > 6 ACLs system using username
Browse files Browse the repository at this point in the history
  • Loading branch information
intel44 committed Dec 28, 2022
1 parent 16bd761 commit 77e29ff
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
25 changes: 24 additions & 1 deletion packages/cli/src/Queue.ts
Expand Up @@ -3,6 +3,7 @@ import { IExecuteResponsePromiseData } from 'n8n-workflow';
import config from '@/config';
import * as ActiveExecutions from '@/ActiveExecutions';
import * as WebhookHelpers from '@/WebhookHelpers';
import { RedisOptions } from 'ioredis';

export type Job = Bull.Job<JobData>;
export type JobQueue = Bull.Queue<JobData>;
Expand Down Expand Up @@ -30,7 +31,29 @@ export class Queue {
this.activeExecutions = ActiveExecutions.getInstance();

const prefix = config.getEnv('queue.bull.prefix');
const redisOptions = config.getEnv('queue.bull.redis');
const redisHost = config.getEnv('queue.bull.redis.host');
const redisUsername = config.getEnv('queue.bull.redis.username');
const redisPassword = config.getEnv('queue.bull.redis.password');
const redisPort = config.getEnv('queue.bull.redis.port');
const redisDB = config.getEnv('queue.bull.redis.db');
// retro-compatibility with redis < 6
// prepare new redis options setting in order to define only set values
const redisOptions: RedisOptions = {};
if (redisHost) {
redisOptions.host = redisHost;
}
if (redisUsername) {
redisOptions.username = redisUsername;
}
if (redisPassword) {
redisOptions.password = redisPassword;
}
if (redisPort) {
redisOptions.port = redisPort;
}
if (redisDB) {
redisOptions.db = redisDB;
}
// Disabling ready check is necessary as it allows worker to
// quickly reconnect to Redis if Redis crashes or is unreachable
// for some time. With it enabled, worker might take minutes to realize
Expand Down
4 changes: 4 additions & 0 deletions packages/cli/src/commands/start.ts
Expand Up @@ -351,6 +351,7 @@ export class Start extends Command {

if (config.getEnv('executions.mode') === 'queue') {
const redisHost = config.getEnv('queue.bull.redis.host');
const redisUsername = config.getEnv('queue.bull.redis.username');
const redisPassword = config.getEnv('queue.bull.redis.password');
const redisPort = config.getEnv('queue.bull.redis.port');
const redisDB = config.getEnv('queue.bull.redis.db');
Expand Down Expand Up @@ -384,6 +385,9 @@ export class Start extends Command {
if (redisHost) {
settings.host = redisHost;
}
if (redisUsername) {
settings.username = redisUsername;
}
if (redisPassword) {
settings.password = redisPassword;
}
Expand Down
4 changes: 4 additions & 0 deletions packages/cli/src/commands/webhook.ts
Expand Up @@ -160,6 +160,7 @@ export class Webhook extends Command {

if (config.getEnv('executions.mode') === 'queue') {
const redisHost = config.getEnv('queue.bull.redis.host');
const redisUsername = config.getEnv('queue.bull.redis.username');
const redisPassword = config.getEnv('queue.bull.redis.password');
const redisPort = config.getEnv('queue.bull.redis.port');
const redisDB = config.getEnv('queue.bull.redis.db');
Expand Down Expand Up @@ -193,6 +194,9 @@ export class Webhook extends Command {
if (redisHost) {
settings.host = redisHost;
}
if (redisUsername) {
settings.username = redisUsername;
}
if (redisPassword) {
settings.password = redisPassword;
}
Expand Down
6 changes: 6 additions & 0 deletions packages/cli/src/config/schema.ts
Expand Up @@ -380,6 +380,12 @@ export const schema = {
default: 10000,
env: 'QUEUE_BULL_REDIS_TIMEOUT_THRESHOLD',
},
username: {
doc: 'Redis Username (needs Redis >= 6)',
format: String,
default: '',
env: 'QUEUE_BULL_REDIS_USERNAME',
},
},
queueRecoveryInterval: {
doc: 'If > 0 enables an active polling to the queue that can recover for Redis crashes. Given in seconds; 0 is disabled. May increase Redis traffic significantly.',
Expand Down

0 comments on commit 77e29ff

Please sign in to comment.