mirror of
https://github.com/andrey271192/Domain_web.git
synced 2026-09-21 14:51:57 +00:00
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>
This commit is contained in:
33
src/lib/redis.ts
Normal file
33
src/lib/redis.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
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 */
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user