mirror of
https://github.com/andrey271192/Domain_web.git
synced 2026-09-21 14:51:57 +00:00
Replace GeoExport static site with Next.js domain intelligence app: real DNS/WHOIS/SSL/HTTP/geo scans, SSE progress, Docker stack, updated install/uninstall scripts, and full documentation. Co-authored-by: Cursor <cursoragent@cursor.com>
34 lines
741 B
TypeScript
34 lines
741 B
TypeScript
import Redis from "ioredis";
|
|
|
|
let redis: Redis | null = null;
|
|
|
|
export function getRedis(): Redis | null {
|
|
const url = process.env.REDIS_URL;
|
|
if (!url) return null;
|
|
if (!redis) {
|
|
redis = new Redis(url, { maxRetriesPerRequest: 3, lazyConnect: true });
|
|
}
|
|
return redis;
|
|
}
|
|
|
|
export async function cacheGet<T>(key: string): Promise<T | null> {
|
|
const r = getRedis();
|
|
if (!r) return null;
|
|
try {
|
|
const val = await r.get(key);
|
|
return val ? (JSON.parse(val) as T) : null;
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export async function cacheSet(key: string, value: unknown, ttlSec = 3600) {
|
|
const r = getRedis();
|
|
if (!r) return;
|
|
try {
|
|
await r.setex(key, ttlSec, JSON.stringify(value));
|
|
} catch {
|
|
/* ignore */
|
|
}
|
|
}
|