forked from FoundKeyGang/FoundKey
allow redis family to be specified as a string
This makes it consistent with `outgoingAddressFamily`, reducing potential confusion. For compatibility reasons, numbers are still permitted for `redis.family` with the following mapping: - `dual` = `0` - `ipv4` = `4` - `ipv6` = `6` Changelog: Changed
This commit is contained in:
parent
59adb0b6e2
commit
5a52532c99
3 changed files with 21 additions and 6 deletions
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue