I can't be bothered to even explain what happene here
This commit is contained in:
39
src/db.ts
39
src/db.ts
@@ -1,14 +1,13 @@
|
||||
import { Redis } from "ioredis";
|
||||
import * as Config from "./config.ts";
|
||||
import Logging from "@proxnet/undead-logging";
|
||||
import process from "node:process";
|
||||
|
||||
const log = new Logging("RedisDB");
|
||||
|
||||
const config = Config.getConfig();
|
||||
if (typeof config == 'undefined') {
|
||||
log.e(`Cannot start: Redis configuration failed`);
|
||||
process.exit(1);
|
||||
Deno.exit(1);
|
||||
}
|
||||
|
||||
let shuttingDown = false;
|
||||
@@ -16,18 +15,19 @@ Deno.addSignalListener('SIGINT', () => {
|
||||
if (shuttingDown) return;
|
||||
shuttingDown = true;
|
||||
log.n('Disconnecting from Redis');
|
||||
if (typeof Database !== 'undefined') Database.quit();
|
||||
Database.quit();
|
||||
});
|
||||
|
||||
export let Database: Redis | undefined;
|
||||
export const Database = new Redis({
|
||||
port: config?.redis.port,
|
||||
host: config?.redis.host,
|
||||
username: config?.redis.username == "" ? undefined : config?.redis.username,
|
||||
password: config?.redis.password == "" ? undefined : config?.redis.password,
|
||||
db: config?.redis.db,
|
||||
lazyConnect: true
|
||||
});
|
||||
export function connectToRedis() {
|
||||
Database = new Redis({
|
||||
port: config?.redis.port,
|
||||
host: config?.redis.host,
|
||||
username: config?.redis.username == "" ? undefined : config?.redis.username,
|
||||
password: config?.redis.password == "" ? undefined : config?.redis.password,
|
||||
db: config?.redis.db
|
||||
});
|
||||
Database.connect();
|
||||
log.i(`Connected to Redis`);
|
||||
}
|
||||
|
||||
@@ -35,13 +35,18 @@ export function buildKey(...args: string[]) {
|
||||
return args.join(':');
|
||||
}
|
||||
export const KeyGroups = {
|
||||
Config: {
|
||||
Root: "config",
|
||||
Dynamic: "dynamic"
|
||||
},
|
||||
Accounts: {
|
||||
Ids: "account-ids",
|
||||
Usernames: "account-usernames",
|
||||
DisplayNames: "account-displaynames",
|
||||
XP: "account-scores",
|
||||
Developers: "account-developers",
|
||||
ProfileImages: "account-images"
|
||||
Root: "accounts",
|
||||
Ids: "ids",
|
||||
Usernames: "usernames",
|
||||
DisplayNames: "displaynames",
|
||||
XP: "scores",
|
||||
Developers: "developers",
|
||||
ProfileImages: "images"
|
||||
}
|
||||
}
|
||||
export * as Redis from "./db.ts";
|
||||
Reference in New Issue
Block a user