aboutsummaryrefslogtreecommitdiffstats
path: root/lib/db.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/db.js')
-rw-r--r--lib/db.js23
1 files changed, 20 insertions, 3 deletions
diff --git a/lib/db.js b/lib/db.js
index d14e4962..c44c7177 100644
--- a/lib/db.js
+++ b/lib/db.js
@@ -41,16 +41,33 @@ export let db = createClient({
},
});
-async function connectWithRetry() {
+export let archive = createClient({
+ url: config.archive,
+ socket: {
+ reconnectStrategy: (retries) => Math.min(retries * 50, 5000),
+ },
+});
+
+async function dbReconnect() {
try {
await db.connect();
} catch (err) {
console.error("Failed to connect to Redis, retrying...", err);
- setTimeout(connectWithRetry, 5000); // Retry after 5 seconds
+ setTimeout(dbReconnect, 5000); // Retry after 5 seconds
+ }
+}
+
+async function archiveReconnect() {
+ try {
+ await archive.connect();
+ } catch (err) {
+ console.error("Failed to connect to Redis, retrying...", err);
+ setTimeout(archiveReconnect, 5000); // Retry after 5 seconds
}
}
-connectWithRetry();
+dbReconnect();
+archiveReconnect();
db.on("error", (e) => {
if (e.message.startsWith("getaddr")) return;