fix(services): 🐛 Fix Redis key-value operations to prevent connection drops and improve reliability

Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
Claude Code 2026-03-20 00:15:48 -07:00
parent f06fdcc58e
commit 8ac98d92ed

View file

@ -1,20 +1,13 @@
import { buildDeploymentRegistry } from '@lilith/service-registry';
import { Injectable, OnModuleInit, OnModuleDestroy, Logger } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { Redis } from 'ioredis';
// Build deployment registry - paths resolved via LILITH_PROJECT_ROOT env var
// Start services via ./run dev to ensure env var is set
const registry = buildDeploymentRegistry({
deploymentsPath: 'deployments/@domains',
sharedServicesPath: 'deployments/shared-services',
});
/**
* RedisService
*
* Provides Redis connectivity for caching throughout the marketplace.
* Uses deployment registry to get Redis configuration (trustedmeet.www.redis).
* Redis port is read from REDIS_PORT env var (set by orchestrator) with a
* fallback to 26379 (trustedmeet.www Redis port from infrastructure/ports.yaml).
*
* Key features:
* - Automatic connection management
@ -32,14 +25,12 @@ export class RedisService implements OnModuleInit, OnModuleDestroy {
async onModuleInit(): Promise<void> {
try {
// Get Redis configuration from deployment registry
// marketplace uses trustedmeet.www deployment's Redis
const redisService = registry.services.get('trustedmeet.www.redis');
const port = this.configService.get<number>('REDIS_PORT') ?? 26379;
const password = this.configService.get<string>('DATABASE_REDIS_PASSWORD');
this.client = new Redis({
host: 'localhost', // Services are always local in dev
port: redisService?.port || 26379,
port,
password: password || undefined,
retryStrategy: (times) => {
if (times > 3) {