From 6f8e3fe36633836d36c5447d78636f370b36cd84 Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Fri, 24 Jun 2022 19:22:19 +0900 Subject: [PATCH] =?UTF-8?q?enhance:=20Redis=E3=82=92ioredis=E3=81=AB?= =?UTF-8?q?=E7=B5=B1=E4=B8=80=E3=81=97=E3=81=A6IPv6=E3=82=B5=E3=83=9D?= =?UTF-8?q?=E3=83=BC=E3=83=88=20(#8869)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Use ioredis, Supports IPv6 host https://github.com/misskey-dev/misskey/issues/8862 * Fix import * order * a * i * fix * flushdb * family * CHANGELOG * redis_version Co-authored-by: syuilo --- .config/example.yml | 1 + CHANGELOG.md | 2 ++ packages/backend/package.json | 2 +- packages/backend/src/config/types.ts | 1 + packages/backend/src/db/postgre.ts | 7 ++++--- packages/backend/src/db/redis.ts | 19 +++++++++---------- packages/backend/src/queue/initialize.ts | 1 + .../server/api/endpoints/admin/server-info.ts | 6 +++++- packages/backend/yarn.lock | 19 ++----------------- 9 files changed, 26 insertions(+), 32 deletions(-) diff --git a/.config/example.yml b/.config/example.yml index ef91c86f5..8b9d9b482 100644 --- a/.config/example.yml +++ b/.config/example.yml @@ -57,6 +57,7 @@ db: redis: host: localhost port: 6379 + #family: 0 # 0=Both, 4=IPv4, 6=IPv6 #pass: example-pass #prefix: example-prefix #db: 1 diff --git a/CHANGELOG.md b/CHANGELOG.md index c4486dd6c..3dc75e6f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,8 @@ You should also include the user name that made the change. - Improve player detection in URL preview @mei23 - Add Badge Image to Push Notification #8012 @tamaina - Client: Removing entries from a clip @futchitwo +- Server: Supports IPv6 on Redis transport. @mei23 + IPv4/IPv6 is used by default. You can tune this behavior via `redis.family`. ### Bugfixes - Server: Fix GenerateVideoThumbnail failed @mei23 diff --git a/packages/backend/package.json b/packages/backend/package.json index 3ac5b7398..b126f723e 100644 --- a/packages/backend/package.json +++ b/packages/backend/package.json @@ -47,6 +47,7 @@ "fluent-ffmpeg": "2.1.2", "got": "12.1.0", "hpagent": "0.1.2", + "ioredis": "4.28.5", "ip-cidr": "3.0.10", "is-svg": "4.3.2", "js-yaml": "4.1.0", @@ -86,7 +87,6 @@ "random-seed": "0.3.0", "ratelimiter": "3.4.1", "re2": "1.17.4", - "redis": "3.1.2", "redis-lock": "0.1.4", "reflect-metadata": "0.1.13", "rename": "1.0.4", diff --git a/packages/backend/src/config/types.ts b/packages/backend/src/config/types.ts index 948545db7..78510c837 100644 --- a/packages/backend/src/config/types.ts +++ b/packages/backend/src/config/types.ts @@ -19,6 +19,7 @@ export type Source = { redis: { host: string; port: number; + family?: number; pass: string; db?: number; prefix?: string; diff --git a/packages/backend/src/db/postgre.ts b/packages/backend/src/db/postgre.ts index 298f6713e..904bbb8b7 100644 --- a/packages/backend/src/db/postgre.ts +++ b/packages/backend/src/db/postgre.ts @@ -192,12 +192,13 @@ export const db = new DataSource({ synchronize: process.env.NODE_ENV === 'test', dropSchema: process.env.NODE_ENV === 'test', cache: !config.db.disableCache ? { - type: 'redis', + type: 'ioredis', options: { host: config.redis.host, port: config.redis.port, + family: config.redis.family == null ? 0 : config.redis.family, password: config.redis.pass, - prefix: `${config.redis.prefix}:query:`, + keyPrefix: `${config.redis.prefix}:query:`, db: config.redis.db || 0, }, } : false, @@ -226,7 +227,7 @@ export async function initDb(force = false) { export async function resetDb() { const reset = async () => { - await redisClient.FLUSHDB(); + await redisClient.flushdb(); const tables = await db.query(`SELECT relname AS "table" FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) WHERE nspname NOT IN ('pg_catalog', 'information_schema') diff --git a/packages/backend/src/db/redis.ts b/packages/backend/src/db/redis.ts index 934604145..49f5bb2ba 100644 --- a/packages/backend/src/db/redis.ts +++ b/packages/backend/src/db/redis.ts @@ -1,16 +1,15 @@ -import * as redis from 'redis'; +import Redis from 'ioredis'; import config from '@/config/index.js'; export function createConnection() { - return redis.createClient( - config.redis.port, - config.redis.host, - { - password: config.redis.pass, - prefix: config.redis.prefix, - db: config.redis.db || 0, - } - ); + return 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, + }); } export const subsdcriber = createConnection(); diff --git a/packages/backend/src/queue/initialize.ts b/packages/backend/src/queue/initialize.ts index 1db118ca9..eef4080af 100644 --- a/packages/backend/src/queue/initialize.ts +++ b/packages/backend/src/queue/initialize.ts @@ -6,6 +6,7 @@ export function initialize(name: string, limitPerSec = -1) { redis: { 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, }, diff --git a/packages/backend/src/server/api/endpoints/admin/server-info.ts b/packages/backend/src/server/api/endpoints/admin/server-info.ts index 9c150420b..85c6fb82e 100644 --- a/packages/backend/src/server/api/endpoints/admin/server-info.ts +++ b/packages/backend/src/server/api/endpoints/admin/server-info.ts @@ -99,12 +99,16 @@ export default define(meta, paramDef, async () => { const fsStats = await si.fsSize(); const netInterface = await si.networkInterfaceDefault(); + const redisServerInfo = await redisClient.info('Server'); + const m = redisServerInfo.match(new RegExp('^redis_version:(.*)', 'm')); + const redis_version = m?.[1]; + return { machine: os.hostname(), os: os.platform(), node: process.version, psql: await db.query('SHOW server_version').then(x => x[0].server_version), - redis: redisClient.server_info.redis_version, + redis: redis_version, cpu: { model: os.cpus()[0].model, cores: os.cpus().length, diff --git a/packages/backend/yarn.lock b/packages/backend/yarn.lock index 4c89fdf05..aa134183a 100644 --- a/packages/backend/yarn.lock +++ b/packages/backend/yarn.lock @@ -2227,11 +2227,6 @@ denque@^1.1.0: resolved "https://registry.yarnpkg.com/denque/-/denque-1.4.1.tgz#6744ff7641c148c3f8a69c307e51235c1f4a37cf" integrity sha512-OfzPuSZKGcgr96rf1oODnfjqBFmr1DVoc/TrItj3Ohe0Ah1C5WX5Baquw/9U9KovnQ88EqmJbD66rKYUQYN1tQ== -denque@^1.5.0: - version "1.5.0" - resolved "https://registry.yarnpkg.com/denque/-/denque-1.5.0.tgz#773de0686ff2d8ec2ff92914316a47b73b1c73de" - integrity sha512-CYiCSgIF1p6EUByQPlGkKnP1M9g0ZV3qMIrqMqZqdwazygIA/YP2vrbcyl1h/WppKJTdl1F85cXIle+394iDAQ== - depd@^1.1.2, depd@~1.1.2: version "1.1.2" resolved "https://registry.yarnpkg.com/depd/-/depd-1.1.2.tgz#9bcd52e14c097763e749b274c4346ed2e560b5a9" @@ -3581,7 +3576,7 @@ internal-slot@^1.0.3: has "^1.0.3" side-channel "^1.0.4" -ioredis@^4.28.5: +ioredis@4.28.5, ioredis@^4.28.5: version "4.28.5" resolved "https://registry.yarnpkg.com/ioredis/-/ioredis-4.28.5.tgz#5c149e6a8d76a7f8fa8a504ffc85b7d5b6797f9f" integrity sha512-3GYo0GJtLqgNXj4YhrisLaNNvWSNwSS2wS4OELGfGxH8I69+XfNdnmV1AyN+ZqMh0i7eX+SWjrwFKDBDgfBC1A== @@ -5805,7 +5800,7 @@ reconnecting-websocket@^4.4.0: resolved "https://registry.yarnpkg.com/reconnecting-websocket/-/reconnecting-websocket-4.4.0.tgz#3b0e5b96ef119e78a03135865b8bb0af1b948783" integrity sha512-D2E33ceRPga0NvTDhJmphEgJ7FUYF0v4lr1ki0csq06OdlxKfugGzN0dSkxM/NfqCxYELK4KcaTOUOjTV6Dcng== -redis-commands@1.7.0, redis-commands@^1.7.0: +redis-commands@1.7.0: version "1.7.0" resolved "https://registry.yarnpkg.com/redis-commands/-/redis-commands-1.7.0.tgz#15a6fea2d58281e27b1cd1acfb4b293e278c3a89" integrity sha512-nJWqw3bTFy21hX/CPKHth6sfhZbdiHP6bTawSgQBlKOVRG7EZkfHbbHwQJnrE4vsQf0CMNE+3gJ4Fmm16vdVlQ== @@ -5845,16 +5840,6 @@ redis@*: "@node-redis/search" "^1.0.2" "@node-redis/time-series" "^1.0.1" -redis@3.1.2: - version "3.1.2" - resolved "https://registry.yarnpkg.com/redis/-/redis-3.1.2.tgz#766851117e80653d23e0ed536254677ab647638c" - integrity sha512-grn5KoZLr/qrRQVwoSkmzdbw6pwF+/rwODtrOr6vuBRiR/f3rjSTGupbF90Zpqm2oenix8Do6RV7pYEkGwlKkw== - dependencies: - denque "^1.5.0" - redis-commands "^1.7.0" - redis-errors "^1.2.0" - redis-parser "^3.0.0" - reflect-metadata@0.1.13, reflect-metadata@^0.1.13: version "0.1.13" resolved "https://registry.yarnpkg.com/reflect-metadata/-/reflect-metadata-0.1.13.tgz#67ae3ca57c972a2aa1642b10fe363fe32d49dc08"