fixed bug Redis Client Connection Leak
This commit is contained in:
parent
d0c5d90033
commit
300f073638
2 changed files with 115 additions and 52 deletions
|
|
@ -123,18 +123,25 @@ export class AuthRoleController extends Controller {
|
|||
|
||||
// เช็คว่าถ้ามีค่า current_holderId ให้ลบ key สิทธิ์ใน redis
|
||||
if (posMaster.current_holderId) {
|
||||
const redisClient = await this.redis.createClient({
|
||||
host: REDIS_HOST,
|
||||
port: REDIS_PORT,
|
||||
});
|
||||
let redisClient;
|
||||
try {
|
||||
redisClient = await this.redis.createClient({
|
||||
host: REDIS_HOST,
|
||||
port: REDIS_PORT,
|
||||
});
|
||||
|
||||
redisClient.del("role_" + posMaster.current_holderId, (err: Error, response: Response) => {
|
||||
if (err) throw err;
|
||||
});
|
||||
redisClient.del("role_" + posMaster.current_holderId, (err: Error, response: Response) => {
|
||||
if (err) throw err;
|
||||
});
|
||||
|
||||
redisClient.del("menu_" + posMaster.current_holderId, (err: Error, response: Response) => {
|
||||
if (err) throw err;
|
||||
});
|
||||
redisClient.del("menu_" + posMaster.current_holderId, (err: Error, response: Response) => {
|
||||
if (err) throw err;
|
||||
});
|
||||
} finally {
|
||||
if (redisClient) {
|
||||
redisClient.quit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new HttpSuccess();
|
||||
|
|
@ -266,14 +273,21 @@ export class AuthRoleController extends Controller {
|
|||
...newAttrs.map((attr) => this.authRoleAttrRepo.save(attr)),
|
||||
]);
|
||||
|
||||
const redisClient = await this.redis.createClient({
|
||||
host: REDIS_HOST,
|
||||
port: REDIS_PORT,
|
||||
});
|
||||
let redisClient;
|
||||
try {
|
||||
redisClient = await this.redis.createClient({
|
||||
host: REDIS_HOST,
|
||||
port: REDIS_PORT,
|
||||
});
|
||||
|
||||
await redisClient.flushdb(function (err: any, succeeded: any) {
|
||||
console.log(succeeded); // will be true if successfull
|
||||
});
|
||||
await redisClient.flushdb(function (err: any, succeeded: any) {
|
||||
console.log(succeeded); // will be true if successfull
|
||||
});
|
||||
} finally {
|
||||
if (redisClient) {
|
||||
redisClient.quit();
|
||||
}
|
||||
}
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue