From ce198c9cf750735bb473ebccb4f97a0844fd01d5 Mon Sep 17 00:00:00 2001 From: "gao.zhiyuan" Date: Thu, 7 Jul 2022 19:44:01 +0800 Subject: [PATCH] redis.Cluster --- code/api/app/lib/service/redis.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/code/api/app/lib/service/redis.js b/code/api/app/lib/service/redis.js index 9097d4b..67af56a 100644 --- a/code/api/app/lib/service/redis.js +++ b/code/api/app/lib/service/redis.js @@ -3,9 +3,20 @@ const redis = require("ioredis") const moment = require('moment') module.exports = async function factory (app, opts) { - let client = new redis(opts.redis.port, opts.redis.host, { - password: opts.redis.pwd, - }); + let client = opts.redis.pwd ? + new redis.Cluster([ + { + host: opts.redis.host, + port: opts.redis.port + } + ], { + redisOptions: { + password: opts.redis.pwd, + }, + }) + : new redis(opts.redis.port, opts.redis.host, { + password: opts.redis.pwd, + }); client.on("error", function (err) { app.fs.logger.error('info', '[FS-AUTH-REDIS]', 'redis connect error.');