test clear redis เผยแพร่ย่อย

This commit is contained in:
Adisak 2026-06-16 13:58:16 +07:00
parent 6319f7206a
commit 61e4bcdf03

View file

@ -8704,42 +8704,42 @@ export class OrganizationController extends Controller {
await queryRunner.commitTransaction(); await queryRunner.commitTransaction();
// Clear Redis cache after successful publish (only menu and role for menu display) // Clear Redis cache after successful publish (only menu and role for menu display)
// const redis = require("redis"); const redis = require("redis");
// const { promisify } = require("util"); const { promisify } = require("util");
// const redisClient = redis.createClient({ const redisClient = redis.createClient({
// host: process.env.REDIS_HOST || "localhost", host: process.env.REDIS_HOST || "localhost",
// port: parseInt(process.env.REDIS_PORT || "6379"), port: parseInt(process.env.REDIS_PORT || "6379"),
// }); });
// const keysAsync = promisify(redisClient.keys).bind(redisClient); const keysAsync = promisify(redisClient.keys).bind(redisClient);
// const delAsync = promisify(redisClient.del).bind(redisClient); const delAsync = promisify(redisClient.del).bind(redisClient);
// try { try {
// // Clear only menu and role cache (affects menu display) // Clear only menu and role cache (affects menu display)
// const menuRolePatterns = ["menu_*", "role_*"]; const menuRolePatterns = ["menu_*", "role_*"];
// let totalCleared = 0; let totalCleared = 0;
// for (const pattern of menuRolePatterns) { for (const pattern of menuRolePatterns) {
// const keys = await keysAsync(pattern); const keys = await keysAsync(pattern);
// if (keys.length > 0) { if (keys.length > 0) {
// // Delete in chunks of 1000 to avoid argument limit // Delete in chunks of 1000 to avoid argument limit
// const chunkSize = 1000; const chunkSize = 1000;
// for (let i = 0; i < keys.length; i += chunkSize) { for (let i = 0; i < keys.length; i += chunkSize) {
// const chunk = keys.slice(i, i + chunkSize); const chunk = keys.slice(i, i + chunkSize);
// await delAsync(...chunk); await delAsync(...chunk);
// } }
// totalCleared += keys.length; totalCleared += keys.length;
// console.log(`[moveDraftToCurrent] Cleared ${keys.length} cache keys for pattern: ${pattern}`); console.log(`[moveDraftToCurrent] Cleared ${keys.length} cache keys for pattern: ${pattern}`);
// } }
// } }
// console.log(`[moveDraftToCurrent] Total cache cleared: ${totalCleared} keys`); console.log(`[moveDraftToCurrent] Total cache cleared: ${totalCleared} keys`);
// } catch (err) { } catch (err) {
// console.error("[moveDraftToCurrent] Error clearing cache:", err); console.error("[moveDraftToCurrent] Error clearing cache:", err);
// } finally { } finally {
// redisClient.quit(); redisClient.quit();
// } }
// // Invalidate memory cache // Invalidate memory cache
// orgStructureCache.invalidate(currentRevisionId); orgStructureCache.invalidate(currentRevisionId);
return new HttpSuccess(summary); return new HttpSuccess(summary);
} catch (error) { } catch (error) {