diff --git a/.config/example.yml b/.config/example.yml index 03ee6e272..e206ccd34 100644 --- a/.config/example.yml +++ b/.config/example.yml @@ -57,7 +57,7 @@ db: redis: host: localhost port: 6379 - #family: 0 # 0=Both, 4=IPv4, 6=IPv6 + #family: dual # can be either a number or string (0/dual, 4/ipv4, 6/ipv6) #pass: example-pass #prefix: example-prefix #db: 1 diff --git a/packages/backend/src/config/types.ts b/packages/backend/src/config/types.ts index 89eafb093..cd74df343 100644 --- a/packages/backend/src/config/types.ts +++ b/packages/backend/src/config/types.ts @@ -1,5 +1,10 @@ /** - * ユーザーが設定する必要のある情報 + * IP address family + */ +export type IpFamily = 'ipv4' | 'ipv6' | 'dual'; + +/** + * Configuration options set up by the user */ export type Source = { repository_url?: string; @@ -19,7 +24,7 @@ export type Source = { redis: { host: string; port: number; - family?: number; + family?: number | IpFamily; pass: string; db?: number; prefix?: string; @@ -47,7 +52,7 @@ export type Source = { id: string; - outgoingAddressFamily?: 'ipv4' | 'ipv6' | 'dual'; + outgoingAddressFamily?: IpFamily; deliverJobConcurrency?: number; inboxJobConcurrency?: number; diff --git a/packages/backend/src/db/redis.ts b/packages/backend/src/db/redis.ts index cd9c81eb3..e576f5e35 100644 --- a/packages/backend/src/db/redis.ts +++ b/packages/backend/src/db/redis.ts @@ -1,11 +1,21 @@ import Redis from 'ioredis'; import config from '@/config/index.js'; +import { IpFamily } from '@/config/types.js'; -export function createConnection() { +function getRedisFamily(family?: IpFamily | number): number { + switch (family) { + case 'ipv4': return 4; + case 'ipv6': return 6; + case 'dual': return 0; + default: return family ?? 0; + } +} + +export function createConnection(): Redis.Redis { return new Redis({ port: config.redis.port, host: config.redis.host, - family: config.redis.family ?? 0, + family: getRedisFamily(config.redis.family), password: config.redis.pass, keyPrefix: `${config.redis.prefix}:`, db: config.redis.db || 0,