I have multiple cloud functions
organized in the following file structure:
root
|_ functions
|___src
|___services
| |___function1.ts
| |___function2.ts
| |___function3.ts
|
|___index.tx
In the index file, I import all the functions and export them for use in the cloud functions:
//index.ts
const function1 = require(./services/function1)
const function2 = require(./services/function2)
const function3 = require(./services/function3)
exports.function1 = function1.function1
exports.function2 = function2.function2
exports.function3 = function3.function3
However, only function1 requires the use of redis. Here is my redis.ts file:
import * as redis from "redis";
const REDISHOST = process.env.REDISHOST || 'localhost';
const REDISPORT = Number(process.env.REDISPORT || 6379);
const redisClient = redis.createClient({
socket: {
host: REDISHOST,
port: REDISPORT,
},
});
redisClient.on('error', err => console.error('ERR:REDIS:', err));
redisClient.connect();
export default redisClient;
This redis client is then imported into function1 as shown below:
import redisClient from "../common/redis"
exports.function1 = onRequest(logic)
The issue arises when deploying function2 and function3, as they also attempt to connect to redis even though the redis client is not imported into them. What could be the mistake in this setup?