comment เคลียร์ redis
This commit is contained in:
parent
c398354208
commit
84fd3fb9e5
2 changed files with 665 additions and 668 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -1737,6 +1737,7 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
|||
}
|
||||
|
||||
async function clearMenuAndRoleCache(): Promise<void> {
|
||||
console.log("[AMQ] clearMenuAndRoleCache: Starting...");
|
||||
const redisClient = redis.createClient({
|
||||
host: REDIS_HOST,
|
||||
port: REDIS_PORT,
|
||||
|
|
@ -1746,35 +1747,28 @@ async function clearMenuAndRoleCache(): Promise<void> {
|
|||
const delAsync = promisify(redisClient.del).bind(redisClient);
|
||||
|
||||
try {
|
||||
const menuKeys = await keysAsync("menu_*");
|
||||
if (menuKeys.length > 0) {
|
||||
await delAsync(...menuKeys);
|
||||
console.log(`[AMQ] Cleared ${menuKeys.length} menu cache keys`);
|
||||
}
|
||||
// Clear menu and role cache (patterns that affect menu display)
|
||||
const menuRolePatterns = ["menu_*", "role_*"];
|
||||
|
||||
const roleKeys = await keysAsync("role_*");
|
||||
if (roleKeys.length > 0) {
|
||||
await delAsync(...roleKeys);
|
||||
console.log(`[AMQ] Cleared ${roleKeys.length} role cache keys`);
|
||||
}
|
||||
|
||||
const posMasterKeys = await keysAsync("posMaster_*");
|
||||
if (posMasterKeys.length > 0) {
|
||||
await delAsync(...posMasterKeys);
|
||||
console.log(`[AMQ] Cleared ${posMasterKeys.length} posMaster cache keys`);
|
||||
}
|
||||
|
||||
const userKeys = await keysAsync("user_*");
|
||||
if (userKeys.length > 0) {
|
||||
await delAsync(...userKeys);
|
||||
console.log(`[AMQ] Cleared ${userKeys.length} user cache keys`);
|
||||
}
|
||||
|
||||
const orgKeys = await keysAsync("org_*");
|
||||
if (orgKeys.length > 0) {
|
||||
await delAsync(...orgKeys);
|
||||
console.log(`[AMQ] Cleared ${orgKeys.length} org cache keys`);
|
||||
for (const pattern of menuRolePatterns) {
|
||||
console.log(`[AMQ] Checking pattern: ${pattern}`);
|
||||
const keys = await keysAsync(pattern);
|
||||
console.log(`[AMQ] Found ${keys.length} keys for pattern: ${pattern}`);
|
||||
if (keys.length > 0) {
|
||||
// Delete in chunks of 1000 to avoid argument limit
|
||||
const chunkSize = 1000;
|
||||
for (let i = 0; i < keys.length; i += chunkSize) {
|
||||
const chunk = keys.slice(i, i + chunkSize);
|
||||
await delAsync(...chunk);
|
||||
}
|
||||
console.log(`[AMQ] Cleared ${keys.length} cache keys for pattern: ${pattern}`);
|
||||
} else {
|
||||
console.log(`[AMQ] No keys found for pattern: ${pattern}`);
|
||||
}
|
||||
}
|
||||
console.log("[AMQ] clearMenuAndRoleCache: Completed successfully");
|
||||
} catch (error) {
|
||||
console.error("[AMQ] clearMenuAndRoleCache ERROR:", error);
|
||||
} finally {
|
||||
redisClient.quit();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue