From adbc483366a9afbb916ec6eaf61bd5d8be6d2f6e Mon Sep 17 00:00:00 2001 From: Simo <13303376+simocsdk@users.noreply.github.com> Date: Fri, 12 Aug 2022 11:56:51 +0200 Subject: [PATCH] add redis custom db index selection Add option to select custom db index if not set, default is 0 --- redisClient.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/redisClient.js b/redisClient.js index 41fef6b..4ff4cf1 100644 --- a/redisClient.js +++ b/redisClient.js @@ -3,11 +3,17 @@ import { createClient } from 'redis'; export async function redisClient() { const REDIS_HOST = process.env.REDIS_HOST || 'redis'; const REDIS_PORT = process.env.REDIS_PORT || 6379; + const REDIS_DB = process.env.REDIS_DB || 0; const client = createClient({ url: `redis://${REDIS_HOST}:${REDIS_PORT}` }); + + client.on('connect', function() { + client.select(REDIS_DB); //select db index + }); client.on('error', (err) => console.log('Redis Client Error', err)); + await client.connect(); return client; }