Files
Domain_web/src/lib/redis.ts
Андрей Бобырев 83168af005 feat: rebrand to Domain Scanner platform
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>
2026-05-24 21:48:32 +03:00

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 */
}
}