33 lines
545 B
TypeScript
33 lines
545 B
TypeScript
|
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
|
||
|
}
|
||
|
|
||
|
}
|