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 Redis from "ioredis"
// ioredis mock is all in memory
const MockRedis = require("ioredis-mock")
// mock-redis doesn't have any typing
let MockRedis: any | undefined
if (env.MOCK_REDIS) {
// ioredis mock is all in memory
MockRedis = require("ioredis-mock")
}
import {
addDbPrefix,
removeDbPrefix,
@ -56,7 +60,7 @@ function connectionError(
* will return the ioredis client which will be ready to use.
*/
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
CLOSED = false
let client = pickClient(selectDb)