Updating mock redis to only import if it is needed.

This commit is contained in:
mike12345567 2023-06-02 11:52:50 +01:00
parent 91f760d7c4
commit ddeb25b68d
1 changed files with 7 additions and 3 deletions

View File

@ -1,7 +1,11 @@
import env from "../environment" import env from "../environment"
import Redis from "ioredis" import Redis from "ioredis"
// mock-redis doesn't have any typing
let MockRedis: any | undefined
if (env.MOCK_REDIS) {
// ioredis mock is all in memory // ioredis mock is all in memory
const MockRedis = require("ioredis-mock") MockRedis = require("ioredis-mock")
}
import { import {
addDbPrefix, addDbPrefix,
removeDbPrefix, removeDbPrefix,
@ -56,7 +60,7 @@ function connectionError(
* will return the ioredis client which will be ready to use. * will return the ioredis client which will be ready to use.
*/ */
function init(selectDb = DEFAULT_SELECT_DB) { function init(selectDb = DEFAULT_SELECT_DB) {
const RedisCore = env.MOCK_REDIS ? MockRedis : Redis const RedisCore = env.MOCK_REDIS && MockRedis ? MockRedis : Redis
let timeout: NodeJS.Timeout let timeout: NodeJS.Timeout
CLOSED = false CLOSED = false
let client = pickClient(selectDb) let client = pickClient(selectDb)