26 lines
613 B
TypeScript
26 lines
613 B
TypeScript
import { createRequire } from 'module'
|
|
import redisConfig from '#config/redis'
|
|
|
|
const require = createRequire(import.meta.url)
|
|
const IORedis = require('ioredis')
|
|
|
|
/**
|
|
* Connects on first use. Ace imports every command at boot, so an eager
|
|
* connection would keep even `node ace list` from exiting.
|
|
*/
|
|
class RedisService {
|
|
private instance?: any
|
|
|
|
public get client(): any {
|
|
this.instance ??= new IORedis(redisConfig.connections.main)
|
|
return this.instance
|
|
}
|
|
|
|
async close() {
|
|
if (this.instance) await this.instance.quit()
|
|
this.instance = undefined
|
|
}
|
|
}
|
|
|
|
export default new RedisService()
|