Base utilities, add README, Redis, Discord integration, db keygroup planning
This commit is contained in:
47
src/db.ts
Normal file
47
src/db.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
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);
|
||||
}
|
||||
|
||||
let shuttingDown = false;
|
||||
Deno.addSignalListener('SIGINT', () => {
|
||||
if (shuttingDown) return;
|
||||
shuttingDown = true;
|
||||
log.n('Disconnecting from Redis');
|
||||
if (typeof Database !== 'undefined') Database.quit();
|
||||
});
|
||||
|
||||
export let Database: Redis | undefined;
|
||||
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
|
||||
});
|
||||
log.i(`Connected to Redis`);
|
||||
}
|
||||
|
||||
export function buildKey(...args: string[]) {
|
||||
return args.join(':');
|
||||
}
|
||||
export const KeyGroups = {
|
||||
Accounts: {
|
||||
Ids: "account-ids",
|
||||
Usernames: "account-usernames",
|
||||
DisplayNames: "account-displaynames",
|
||||
XP: "account-scores",
|
||||
Developers: "account-developers",
|
||||
ProfileImages: "account-images"
|
||||
}
|
||||
}
|
||||
export * as Redis from "./db.ts";
|
||||
Reference in New Issue
Block a user