From e7c0f26a0fdbdf80a1eb8fa93191b54fa24d59c8 Mon Sep 17 00:00:00 2001 From: sousuke0422 Date: Sat, 30 Jul 2022 02:39:33 +0900 Subject: [PATCH] refactor: use ioredis --- .config/example.yml | 1 + src/config/types.ts | 1 + src/db/redis.ts | 21 ++++++++++----------- src/queue/initialize.ts | 2 ++ 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/.config/example.yml b/.config/example.yml index cd0b87b6f1..1e602fbf91 100644 --- a/.config/example.yml +++ b/.config/example.yml @@ -58,6 +58,7 @@ redis: #path: /var/run/redis/redis-server.sock #unixsocket host: localhost port: 6379 + #family: 0 # 0=Both, 4=IPv4, 6=IPv6 #pass: example-pass #prefix: example-prefix #db: 1 diff --git a/src/config/types.ts b/src/config/types.ts index 10a8b4a370..047784708f 100644 --- a/src/config/types.ts +++ b/src/config/types.ts @@ -22,6 +22,7 @@ export type Source = { path: string; host: string; port: number; + family?: number; pass: string; db?: number; prefix?: string; diff --git a/src/db/redis.ts b/src/db/redis.ts index 5c45457262..46119ba126 100644 --- a/src/db/redis.ts +++ b/src/db/redis.ts @@ -1,23 +1,22 @@ -import * as redis from 'redis'; +import * as Redis from 'ioredis'; import config from '../config'; export function createConnection() { if (config.redis.path == null) { - return redis.createClient( - config.redis.port, - config.redis.host, - { + return new Redis({ + port: config.redis.port, + host: config.redis.host, + family: config.redis.family == null ? 0 : config.redis.family, password: config.redis.pass, - prefix: config.redis.prefix, + keyPrefix: `${config.redis.prefix}:`, db: config.redis.db || 0 } ); } else { - return redis.createClient( - config.redis.path, - { + return new Redis({ + path: config.redis.path, password: config.redis.pass, - prefix: config.redis.prefix, + keyPrefix: `${config.redis.prefix}:`, db: config.redis.db || 0 } ); @@ -25,6 +24,6 @@ export function createConnection() { } export const subsdcriber = createConnection(); -subsdcriber.subscribe(config.host); +//subsdcriber.subscribe(config.host); export const redisClient = createConnection(); diff --git a/src/queue/initialize.ts b/src/queue/initialize.ts index fe564a6d15..7ce26faeca 100644 --- a/src/queue/initialize.ts +++ b/src/queue/initialize.ts @@ -8,12 +8,14 @@ if (config.redis.path == null) { redisOpts = { port: config.redis.port, host: config.redis.host, + family: config.redis.family == null ? 0 : config.redis.family, password: config.redis.pass, db: config.redis.db || 0, } } else { redisOpts = { path: config.redis.path, + family: config.redis.family == null ? 0 : config.redis.family, password: config.redis.pass, db: config.redis.db || 0, }