yappa kousuru
This commit is contained in:
parent
8a0a54700c
commit
11197ccd0b
|
@ -82,8 +82,7 @@ redis:
|
|||
#pass: example-pass
|
||||
#prefix: example-prefix
|
||||
#db: 1
|
||||
# Extra ioredis options
|
||||
#extra:
|
||||
# You can specify more ioredis options...
|
||||
#username: example-username
|
||||
|
||||
#redisForPubsub:
|
||||
|
@ -93,8 +92,7 @@ redis:
|
|||
# #pass: example-pass
|
||||
# #prefix: example-prefix
|
||||
# #db: 1
|
||||
# # Extra ioredis options
|
||||
# #extra:
|
||||
# # You can specify more ioredis options...
|
||||
# #username: example-username
|
||||
|
||||
#redisForJobQueue:
|
||||
|
@ -104,8 +102,7 @@ redis:
|
|||
# #pass: example-pass
|
||||
# #prefix: example-prefix
|
||||
# #db: 1
|
||||
# # Extra ioredis options
|
||||
# #extra:
|
||||
# # You can specify more ioredis options...
|
||||
# #username: example-username
|
||||
|
||||
# ┌───────────────────────────┐
|
||||
|
|
|
@ -2,15 +2,7 @@ import Redis from 'ioredis';
|
|||
import { loadConfig } from './built/config.js';
|
||||
|
||||
const config = loadConfig();
|
||||
const redis = new Redis({
|
||||
port: config.redis.port,
|
||||
host: config.redis.host,
|
||||
family: config.redis.family == null ? 0 : config.redis.family,
|
||||
password: config.redis.pass,
|
||||
keyPrefix: `${config.redis.prefix}:`,
|
||||
db: config.redis.db ?? 0,
|
||||
...(config.redis.extra ?? {}),
|
||||
});
|
||||
const redis = new Redis(config.redis);
|
||||
|
||||
redis.on('connect', () => redis.disconnect());
|
||||
redis.on('error', (e) => {
|
||||
|
|
|
@ -41,15 +41,7 @@ const $meilisearch: Provider = {
|
|||
const $redis: Provider = {
|
||||
provide: DI.redis,
|
||||
useFactory: (config: Config) => {
|
||||
return new Redis.Redis({
|
||||
port: config.redis.port,
|
||||
host: config.redis.host,
|
||||
family: config.redis.family == null ? 0 : config.redis.family,
|
||||
password: config.redis.pass,
|
||||
keyPrefix: `${config.redis.prefix}:`,
|
||||
db: config.redis.db ?? 0,
|
||||
...(config.redis.extra ?? {}),
|
||||
});
|
||||
return new Redis.Redis(config.redis);
|
||||
},
|
||||
inject: [DI.config],
|
||||
};
|
||||
|
@ -57,15 +49,7 @@ const $redis: Provider = {
|
|||
const $redisForPub: Provider = {
|
||||
provide: DI.redisForPub,
|
||||
useFactory: (config: Config) => {
|
||||
const redis = new Redis.Redis({
|
||||
port: config.redisForPubsub.port,
|
||||
host: config.redisForPubsub.host,
|
||||
family: config.redisForPubsub.family == null ? 0 : config.redisForPubsub.family,
|
||||
password: config.redisForPubsub.pass,
|
||||
keyPrefix: `${config.redisForPubsub.prefix}:`,
|
||||
db: config.redisForPubsub.db ?? 0,
|
||||
...(config.redisForPubsub.extra ?? {}),
|
||||
});
|
||||
const redis = new Redis.Redis(config.redisForPubsub);
|
||||
return redis;
|
||||
},
|
||||
inject: [DI.config],
|
||||
|
@ -74,15 +58,7 @@ const $redisForPub: Provider = {
|
|||
const $redisForSub: Provider = {
|
||||
provide: DI.redisForSub,
|
||||
useFactory: (config: Config) => {
|
||||
const redis = new Redis.Redis({
|
||||
port: config.redisForPubsub.port,
|
||||
host: config.redisForPubsub.host,
|
||||
family: config.redisForPubsub.family == null ? 0 : config.redisForPubsub.family,
|
||||
password: config.redisForPubsub.pass,
|
||||
keyPrefix: `${config.redisForPubsub.prefix}:`,
|
||||
db: config.redisForPubsub.db ?? 0,
|
||||
...(config.redisForPubsub.extra ?? {}),
|
||||
});
|
||||
const redis = new Redis.Redis(config.redisForPubsub);
|
||||
redis.subscribe(config.host);
|
||||
return redis;
|
||||
},
|
||||
|
|
|
@ -8,6 +8,15 @@ import { dirname, resolve } from 'node:path';
|
|||
import * as yaml from 'js-yaml';
|
||||
import type { RedisOptions } from 'ioredis';
|
||||
|
||||
type RedisOptionsSource = Partial<RedisOptions> & {
|
||||
host: string;
|
||||
port: number;
|
||||
family?: number;
|
||||
pass: string;
|
||||
db?: number;
|
||||
prefix?: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* ユーザーが設定する必要のある情報
|
||||
*/
|
||||
|
@ -36,33 +45,9 @@ export type Source = {
|
|||
user: string;
|
||||
pass: string;
|
||||
}[];
|
||||
redis: {
|
||||
host: string;
|
||||
port: number;
|
||||
family?: number;
|
||||
pass: string;
|
||||
db?: number;
|
||||
prefix?: string;
|
||||
extra?: RedisOptions;
|
||||
};
|
||||
redisForPubsub?: {
|
||||
host: string;
|
||||
port: number;
|
||||
family?: number;
|
||||
pass: string;
|
||||
db?: number;
|
||||
prefix?: string;
|
||||
extra?: RedisOptions;
|
||||
};
|
||||
redisForJobQueue?: {
|
||||
host: string;
|
||||
port: number;
|
||||
family?: number;
|
||||
pass: string;
|
||||
db?: number;
|
||||
prefix?: string;
|
||||
extra?: RedisOptions;
|
||||
};
|
||||
redis: RedisOptionsSource;
|
||||
redisForPubsub?: RedisOptionsSource;
|
||||
redisForJobQueue?: RedisOptionsSource;
|
||||
meilisearch?: {
|
||||
host: string;
|
||||
port: string;
|
||||
|
@ -123,8 +108,9 @@ export type Mixin = {
|
|||
mediaProxy: string;
|
||||
externalMediaProxyEnabled: boolean;
|
||||
videoThumbnailGenerator: string | null;
|
||||
redisForPubsub: NonNullable<Source['redisForPubsub']>;
|
||||
redisForJobQueue: NonNullable<Source['redisForJobQueue']>;
|
||||
redis: RedisOptions;
|
||||
redisForPubsub: RedisOptions;
|
||||
redisForJobQueue: RedisOptions;
|
||||
};
|
||||
|
||||
export type Config = Source & Mixin;
|
||||
|
@ -186,9 +172,9 @@ export function loadConfig() {
|
|||
config.videoThumbnailGenerator.endsWith('/') ? config.videoThumbnailGenerator.substring(0, config.videoThumbnailGenerator.length - 1) : config.videoThumbnailGenerator
|
||||
: null;
|
||||
|
||||
if (!config.redis.prefix) config.redis.prefix = mixin.host;
|
||||
if (config.redisForPubsub == null) config.redisForPubsub = config.redis;
|
||||
if (config.redisForJobQueue == null) config.redisForJobQueue = config.redis;
|
||||
mixin.redis = convertRedisOptions(config.redis, mixin.host);
|
||||
mixin.redisForPubsub = config.redisForPubsub ? convertRedisOptions(config.redisForPubsub, mixin.host) : mixin.redis;
|
||||
mixin.redisForJobQueue = config.redisForJobQueue ? convertRedisOptions(config.redisForJobQueue, mixin.host) : mixin.redis;
|
||||
|
||||
return Object.assign(config, mixin);
|
||||
}
|
||||
|
@ -200,3 +186,12 @@ function tryCreateUrl(url: string) {
|
|||
throw new Error(`url="${url}" is not a valid URL.`);
|
||||
}
|
||||
}
|
||||
|
||||
function convertRedisOptions(options: RedisOptionsSource, host: string): RedisOptions {
|
||||
return {
|
||||
...options,
|
||||
family: options.family == null ? 0 : options.family,
|
||||
keyPrefix: `${options.prefix ?? host}:`,
|
||||
db: options.db ?? 0,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -14,14 +14,7 @@ export const QUEUE = {
|
|||
|
||||
export function baseQueueOptions(config: Config, queueName: typeof QUEUE[keyof typeof QUEUE]): Bull.QueueOptions {
|
||||
return {
|
||||
connection: {
|
||||
port: config.redisForJobQueue.port,
|
||||
host: config.redisForJobQueue.host,
|
||||
family: config.redisForJobQueue.family == null ? 0 : config.redisForJobQueue.family,
|
||||
password: config.redisForJobQueue.pass,
|
||||
db: config.redisForJobQueue.db ?? 0,
|
||||
...(config.redisForJobQueue.extra ?? {}),
|
||||
},
|
||||
connection: config.redisForJobQueue,
|
||||
prefix: config.redisForJobQueue.prefix ? `${config.redisForJobQueue.prefix}:queue:${queueName}` : `queue:${queueName}`,
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue