添加redis和rpc功能
This commit is contained in:
32
utils/redis/driver.ts
Normal file
32
utils/redis/driver.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
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
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user