diff --git a/src/controllers/PosMasterActController.ts b/src/controllers/PosMasterActController.ts index 3b5d3196..4d328f99 100644 --- a/src/controllers/PosMasterActController.ts +++ b/src/controllers/PosMasterActController.ts @@ -325,16 +325,33 @@ export class PosMasterActController extends Controller { // ลบ Redis cache ของคนที่เป็น acting if (posMasterAct != null && posMasterAct.posMasterChild?.current_holderId) { const profileId = posMasterAct.posMasterChild.current_holderId; - const redisClient = await this.redis.createClient({ + const redisClient = this.redis.createClient({ host: REDIS_HOST, port: REDIS_PORT, }); const delAsync = promisify(redisClient.del).bind(redisClient); - await delAsync("role_" + profileId); - await delAsync("menu_" + profileId); + const quitAsync = promisify(redisClient.quit).bind(redisClient); + try { + const [roleDeleted, menuDeleted] = await Promise.all([ + delAsync("role_" + profileId), + delAsync("menu_" + profileId), + ]); - redisClient.quit(); + if (roleDeleted === 0) { + console.warn(`[PosMasterActController] Redis key not found: role_${profileId}`); + } + if (menuDeleted === 0) { + console.warn(`[PosMasterActController] Redis key not found: menu_${profileId}`); + } + } catch (error) { + console.error( + `[PosMasterActController] Redis delete error for profile ${profileId}:`, + error, + ); + } finally { + await quitAsync(); + } } return new HttpSuccess(); @@ -868,10 +885,28 @@ export class PosMasterActController extends Controller { }); const delAsync = promisify(redisClient.del).bind(redisClient); - await delAsync("role_" + profileId); - await delAsync("menu_" + profileId); + const quitAsync = promisify(redisClient.quit).bind(redisClient); - redisClient.quit(); + try { + const [roleDeleted, menuDeleted] = await Promise.all([ + delAsync("role_" + profileId), + delAsync("menu_" + profileId), + ]); + + if (roleDeleted === 0) { + console.warn(`[PosMasterActController] Redis key not found: role_${profileId}`); + } + if (menuDeleted === 0) { + console.warn(`[PosMasterActController] Redis key not found: menu_${profileId}`); + } + } catch (error) { + console.error( + `[PosMasterActController] Redis delete error for profile ${profileId}:`, + error, + ); + } finally { + await quitAsync(); + } }), ); }