diff options
| author | tamaina <tamaina@hotmail.co.jp> | 2023-07-20 19:50:31 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-20 19:50:31 +0900 |
| commit | 0a06eb27da747c22ff8403ba9bf9f1704eb65425 (patch) | |
| tree | 9bf1b6a77f57d0d0208f4a79effea3eb874915c5 /packages/backend/src/config.ts | |
| parent | refactor(frontend): use nodemon for storybook (#11297) (diff) | |
| download | misskey-0a06eb27da747c22ff8403ba9bf9f1704eb65425.tar.gz misskey-0a06eb27da747c22ff8403ba9bf9f1704eb65425.tar.bz2 misskey-0a06eb27da747c22ff8403ba9bf9f1704eb65425.zip | |
enhance(backend): 設定ファイルでioredisの全てのオプションを指定可能に (#11329)
* enhance(backend): 設定ファイルでioredisの全てのオプションを指定可能に
* yappa kousuru
* fix
* fix?
* fix
* Revert "fix"
This reverts commit 227f19ff3afcbbd560b831493975206263a1a5a3.
* fix
Diffstat (limited to 'packages/backend/src/config.ts')
| -rw-r--r-- | packages/backend/src/config.ts | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/packages/backend/src/config.ts b/packages/backend/src/config.ts index 8c312256da..bbacfe31a7 100644 --- a/packages/backend/src/config.ts +++ b/packages/backend/src/config.ts @@ -6,6 +6,16 @@ import * as fs from 'node:fs'; import { fileURLToPath } from 'node:url'; 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; +}; /** * ユーザーが設定する必要のある情報 @@ -35,30 +45,9 @@ export type Source = { user: string; pass: string; }[]; - redis: { - host: string; - port: number; - family?: number; - pass: string; - db?: number; - prefix?: string; - }; - redisForPubsub?: { - host: string; - port: number; - family?: number; - pass: string; - db?: number; - prefix?: string; - }; - redisForJobQueue?: { - host: string; - port: number; - family?: number; - pass: string; - db?: number; - prefix?: string; - }; + redis: RedisOptionsSource; + redisForPubsub?: RedisOptionsSource; + redisForJobQueue?: RedisOptionsSource; meilisearch?: { host: string; port: string; @@ -119,8 +108,9 @@ export type Mixin = { mediaProxy: string; externalMediaProxyEnabled: boolean; videoThumbnailGenerator: string | null; - redisForPubsub: NonNullable<Source['redisForPubsub']>; - redisForJobQueue: NonNullable<Source['redisForJobQueue']>; + redis: RedisOptions & RedisOptionsSource; + redisForPubsub: RedisOptions & RedisOptionsSource; + redisForJobQueue: RedisOptions & RedisOptionsSource; }; export type Config = Source & Mixin; @@ -182,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); } @@ -196,3 +186,13 @@ function tryCreateUrl(url: string) { throw new Error(`url="${url}" is not a valid URL.`); } } + +function convertRedisOptions(options: RedisOptionsSource, host: string): RedisOptions & RedisOptionsSource { + return { + ...options, + prefix: options.prefix ?? host, + family: options.family == null ? 0 : options.family, + keyPrefix: `${options.prefix ?? host}:`, + db: options.db ?? 0, + }; +} |