Skip to content

Commit

Permalink
fix: cannot connect redis sentinel (#1511)
Browse files Browse the repository at this point in the history
  • Loading branch information
lmquang authored Oct 4, 2023
1 parent fff5199 commit 06a3e2d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
11 changes: 6 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion src/adapters/fetcher/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import { attachAuthorization, convertToSnakeCase, makeLog } from "./utils"
import toCurl from "fetch-to-curl"
import { kafkaQueue } from "queue/kafka/queue"
import { stack } from "utils/stack-trace"

import {
CACHE_TTL_SECONDS,
FETCH_TIMEOUT_SECONDS,
REDIS_HOST,
REDIS_DB,
REDIS_MASTER_NAME,
TEST,
} from "env"
import {
Expand Down Expand Up @@ -54,7 +56,14 @@ let cache = {

if (!TEST) {
logger.info("Connecting to Redis...")
const redis = new Redis(`redis://${REDIS_HOST}/${REDIS_DB}`)

let redis = new Redis(`redis://${REDIS_HOST}/${REDIS_DB}`)
// add redis sentinel support
if (REDIS_MASTER_NAME != "") {
redis = new Redis(`redis://${REDIS_HOST}/${REDIS_DB}`, {
name: REDIS_MASTER_NAME,
})
}

redis
.on("ready", () => {
Expand Down
1 change: 1 addition & 0 deletions src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export const FETCH_TIMEOUT_SECONDS = process.env.FETCH_TIMEOUT_SECONDS || 5
export const CACHE_TTL_SECONDS = process.env.CACHE_TTL_SECONDS || 1800
export const REDIS_HOST = process.env.REDIS_HOST || "localhost:6379"
export const REDIS_DB = process.env.REDIS_DB || "0"
export const REDIS_MASTER_NAME = process.env.REDIS_MASTER_NAME || ""

export const MOCHI_GUESS_API_KEY = process.env.MOCHI_GUESS_API_KEY || ""
export const MOCHI_GUESS_API_HOST = process.env.MOCHI_GUESS_API_HOST || ""

0 comments on commit 06a3e2d

Please sign in to comment.