Skip to content

Commit

Permalink
redis: handle errors to prevent crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharthvp committed Mar 29, 2024
1 parent 454400d commit 2f5f8e4
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions redis.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as redis from 'redis';
import * as asyncRedis from "async-redis";
import { onToolforge, readFile } from "./utils";
import { log } from "./botbase";

// Source: https://github.com/moaxaca/async-redis (MIT)
// for some reason the Promisified type that we need isn't exported from there
Expand Down Expand Up @@ -53,6 +54,10 @@ export function getRedisConfig(config: redis.ClientOpts = {}): redis.ClientOpts
export function getRedisInstance(): Redis {
if (!instance) {
instance = createRedisClient();
instance.on('error', (err: Error) => {
log(`[E] Redis error`);
log(err);
});
}
return instance;
}

0 comments on commit 2f5f8e4

Please sign in to comment.