mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
make redis client conditional
This commit is contained in:
@@ -1,3 +1,12 @@
|
||||
import { Redis } from "ioredis"
|
||||
|
||||
export const redisClient = new Redis(process.env.REDIS_URL as string);
|
||||
let redisClient: Redis | null;
|
||||
|
||||
if (process.env.REDIS_URL) {
|
||||
redisClient = new Redis(process.env.REDIS_URL as string);
|
||||
} else {
|
||||
console.warn("Redis URL not set, skipping Redis initialization.");
|
||||
redisClient = null
|
||||
}
|
||||
|
||||
export { redisClient }
|
||||
@@ -689,7 +689,7 @@ export const backfillUserAuthMethods = async () => {
|
||||
export const backfillPermission = async () => {
|
||||
const lockKey = "backfill_permission_lock";
|
||||
const timeout = 5000; // Lock timeout in milliseconds
|
||||
const lock = await redisClient.set(lockKey, 1, "PX", timeout, "NX");
|
||||
const lock = await redisClient?.set(lockKey, 1, "PX", timeout, "NX");
|
||||
|
||||
if (lock) {
|
||||
try {
|
||||
@@ -807,7 +807,7 @@ export const backfillPermission = async () => {
|
||||
} catch (error) {
|
||||
console.error("An error occurred when running script [backfillPermission]:", error);
|
||||
} finally {
|
||||
await redisClient.del(lockKey);
|
||||
await redisClient?.del(lockKey);
|
||||
}
|
||||
} else {
|
||||
console.info("Could not acquire lock for script [backfillPermission], skipping");
|
||||
|
||||
Reference in New Issue
Block a user