Skip to content

Commit

Permalink
fix: redis sentinels
Browse files Browse the repository at this point in the history
  • Loading branch information
devthejo committed Mar 5, 2025
1 parent 2347c81 commit ad6b289
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
7 changes: 6 additions & 1 deletion .kontinuous/env/preprod/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ app:
MAILER_SMTP_SSL: "False"
NODE_ENV: production
# EMAIL_LOGIN: "True"
REDIS_HOST: "redis"
REDIS_SENTINEL_HOSTS: |
[
{ host: "redis-node-0.redis-headless", port: 26379 },
{ host: "redis-node-1.redis-headless", port: 26379 },
{ host: "redis-node-2.redis-headless", port: 26379 }
]
resources:
requests:
cpu: 20m
Expand Down
7 changes: 6 additions & 1 deletion .kontinuous/env/prod/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ api:
app:
vars:
MAILER_ENABLE: "True"
REDIS_HOST: "redis"
REDIS_SENTINEL_HOSTS: |
[
{ host: "redis-node-0.redis-headless", port: 26379 },
{ host: "redis-node-1.redis-headless", port: 26379 },
{ host: "redis-node-2.redis-headless", port: 26379 }
]
redirectFrom:
- "egapro.fabrique.social.gouv.fr"
- "index-egapro.travail.gouv.fr"
Expand Down
17 changes: 13 additions & 4 deletions packages/app/src/api/core-domain/infra/companies-store.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
import { logger } from "@api/utils/pino";
import * as crypto from "crypto";
import Redis from "ioredis";
import Redis, { type RedisOptions } from "ioredis";

export type Company = { label: string | null; siren: string };

// Configure Redis connection based on environment variables or defaults
const redisOptions = {
host: process.env.REDIS_HOST || "localhost",
port: parseInt(process.env.REDIS_PORT || "6379", 10),
const redisOptions: RedisOptions = {
password: process.env.REDIS_PASSWORD,
};

if (process.env.REDIS_SENTINEL_HOSTS) {
try {
redisOptions.sentinels = JSON.parse(process.env.REDIS_SENTINEL_HOSTS);
} catch (error) {
logger.error({ error }, "Failed to parse REDIS_SENTINEL_HOSTS, falling back to direct connection");
}
} else {
redisOptions.host = process.env.REDIS_HOST || "localhost";
redisOptions.port = parseInt(process.env.REDIS_PORT || "6379", 10);
}

const maxTtl = 60 * 60 * 48;

// Create Redis client
Expand Down

0 comments on commit ad6b289

Please sign in to comment.