2021-07-07 18:15:53 +02:00
|
|
|
const Client = require("./index")
|
|
|
|
const utils = require("./utils")
|
2021-07-06 19:10:04 +02:00
|
|
|
|
|
|
|
let userClient, sessionClient
|
|
|
|
|
|
|
|
async function init() {
|
|
|
|
userClient = await new Client(utils.Databases.USER_CACHE).init()
|
|
|
|
sessionClient = await new Client(utils.Databases.SESSIONS).init()
|
|
|
|
}
|
|
|
|
|
|
|
|
process.on("exit", async () => {
|
|
|
|
if (userClient) await userClient.finish()
|
|
|
|
if (sessionClient) await sessionClient.finish()
|
|
|
|
})
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
getUserClient: async () => {
|
|
|
|
if (!userClient) {
|
|
|
|
await init()
|
|
|
|
}
|
|
|
|
return userClient
|
|
|
|
},
|
|
|
|
getSessionClient: async () => {
|
|
|
|
if (!sessionClient) {
|
|
|
|
await init()
|
|
|
|
}
|
|
|
|
return sessionClient
|
|
|
|
},
|
|
|
|
}
|