Skip to content

Commit

Permalink
fix: handle redis connection failure
Browse files Browse the repository at this point in the history
  • Loading branch information
esroyo committed Feb 27, 2024
1 parent 4cc7366 commit 4b47e0c
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ export const services = {
if (!instances.cache) {
const REDIS_HOSTNAME = Deno.env.get('CACHE_REDIS_HOSTNAME');
if (REDIS_HOSTNAME) {
instances.cache = new RedisCache(redis.connect({
const redisPromise = redis.connect({
hostname: REDIS_HOSTNAME,
}));
});
instances.cache = new RedisCache(redisPromise);
redisPromise.catch(() => {
instances.cache?.close();
delete instances.cache;
});
} else {
const denoKv: Promise<Deno.Kv> = Deno.openKv();
instances.cache = new DenoKvCache(denoKv);
Expand Down

0 comments on commit 4b47e0c

Please sign in to comment.