express-template/utils/redis/driver.ts

33 lines
545 B
TypeScript
Raw Normal View History

2021-08-29 10:31:21 +00:00
import Redis from 'ioredis'
const clients = new Map<string,RedisClientDriver>()
export class RedisClientDriver extends Redis {
constructor (
/**
* redis
*/
private readonly _name:string,
host:string,
port:number,
password:string,
db:number
) {
super(port,host,{
password,
db
})
clients.set(this.name,this)
}
static getClient (name:string):RedisClientDriver|null {
return clients.get(name) || null
}
get name ():string {
return this._name
}
}