Module exposing: initRedis, getRedis, closeRedis
// Source: https://github.com/Eric-Song-Nop/mobvibe | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
// Provided via justclaw.it.com; keep this notice with the code.
import { Redis } from "ioredis";
import { logger } from "../lib/logger.js";
let redis: Redis | null = null;
export type { Redis };
/**
* Initialize Redis connection from REDIS_URL.
* Returns null if REDIS_URL is not set or connection fails (graceful degradation).
*/
export async function initRedis(
redisUrl: string | undefined,
): Promise<Redis | null> {
if (!redisUrl) {
logger.info("redis_disabled_no_url");
return null;
}
try {
const client = new Redis(redisUrl, {
maxRetriesPerRequest: 3,
retryStrategy(times) {
if (times > 5) {
logger.warn({ times },
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key