// @ts-nocheck import * as bluebird from 'bluebird'; import * as redisClient from 'redis'; import * as commander from 'commander'; import * as fs from 'fs'; bluebird.promisifyAll(redisClient.RedisClient.prototype); bluebird.promisifyAll(redisClient.Multi.prototype); const files = []; (async () => { commander .option('-h, --host ', 'Redis host to work with') .option('-p, --port ', 'The port on which to connect') .option('-d, --db ', 'The Redis db used.') .option('-o, --org-slug ', 'Org slug') .option('--all', 'Delete all orgs all cache') .option('-nd, --no-dry-run', 'Don\'t run in dry run mode') .option('-f, --files-file ', 'A file containing the files that need to be removed one per line') .option('-z, --single-file ', 'The url of the file you want to remove from cache') .option('-s, --chunk-size ', 'Size of chunk for scan. (Default: 10000)') .option('-j, --deletion-parallelism ', 'Deletion parallelism') .parse(process.argv); if (!commander.orgSlug && !commander.all) { console.log('You need to specify the org slug for which you want to evict or specify all'); return; } const orgSlug = commander.orgSlug; const prefix = orgSlug ? `mv-cache:${orgSlug}:*` : 'mv-cache:*'; if (!commander.host) { console.log('Please specify the redis host'); return; } const config = { host: commander.host, port: commander.port || '6379', database: commander.db || 7, }; const redis: any = redisClient.createClient(config); if (config.database) { redis.select(config.database); } if (commander.filesFile) { const newFiles = fs.readFileSync(commander.filesFile).toString().split('\n').map(x => x.trim()).filter(x => !!x); Array.prototype.push.apply(files, newFiles); } if (commander.singleFile) { files.push(commander.singleFile.trim()); } const chunkSize = commander.chunkSize || '10000'; let parallelism = 10; if (commander.deletionParallelism) { parallelism = parseInt(commander.deletionParallelism, 10) || 10; } if (commander.dryRun) { console.log('Running in dry run mode.'); } let cursor = '0'; do { const response = await redis.scanAsync(cursor, 'MATCH', prefix, 'COUNT', chunkSize); cursor = response[0]; const keys = response[1]; await bluebird.map(keys, async (key: string) => { const id = key.split(':')[2]; if (id === 'maxStorageSize' || id === 'LRU' || id === 'storageSize' || key.split(':').length !== 3) { return; } const segment = await redis.hgetallAsync(key); if (segment.totalStartTime < 1) { console.dir(segment, { colors: true }); } // console.log(segment.totalStartTime, id); }, { concurrency: parallelism }); } while (cursor !== '0'); process.exit(0); })();