You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
/**
* 清空 Redis 开发库(本地干净环境,快速失败)
* 用法: npx tsx scripts/dev/flush-redis.ts
*/
import Redis from "ioredis" ;
import { loadDevEnv } from "../../lib/dev-env" ;
loadDevEnv ( ) ;
const FLUSH_TIMEOUT_MS = Number ( process . env . REDIS_FLUSH_TIMEOUT_MS ? ? 3000 ) ;
async function main ( ) : Promise < void > {
const url = process . env . REDIS_URL ;
if ( ! url ) {
throw new Error ( "REDIS_URL 未配置" ) ;
}
const redis = new Redis ( url , {
family : 4 ,
lazyConnect : true ,
connectTimeout : FLUSH_TIMEOUT_MS ,
maxRetriesPerRequest : 1 ,
enableReadyCheck : true ,
retryStrategy : ( ) = > null ,
} ) ;
try {
await redis . connect ( ) ;
await redis . flushdb ( ) ;
console . log ( "Redis FLUSHDB 完成" ) ;
} finally {
await redis . quit ( ) . catch ( ( ) = > undefined ) ;
}
}
main ( ) . catch ( ( error : unknown ) = > {
console . error ( error instanceof Error ? error.message : error ) ;
process . exit ( 1 ) ;
} ) ;