refactoring continuing

This commit is contained in:
Boki 2025-06-22 08:27:54 -04:00
parent 742e590382
commit a0a3b26177
20 changed files with 394 additions and 798 deletions

View file

@ -1,5 +1,4 @@
import Redis from 'ioredis';
import { getLogger } from '@stock-bot/logger';
import { RedisConnectionManager } from './connection-manager';
import { CacheOptions, CacheProvider, CacheStats } from './types';
@ -8,7 +7,7 @@ import { CacheOptions, CacheProvider, CacheStats } from './types';
*/
export class RedisCache implements CacheProvider {
private redis: Redis;
private logger = getLogger('redis-cache');
private logger: any;
private defaultTTL: number;
private keyPrefix: string;
private enableMetrics: boolean;
@ -29,6 +28,7 @@ export class RedisCache implements CacheProvider {
this.defaultTTL = options.ttl ?? 3600; // 1 hour default
this.keyPrefix = options.keyPrefix ?? 'cache:';
this.enableMetrics = options.enableMetrics ?? true;
this.logger = options.logger || console; // Use provided logger or console as fallback
// Get connection manager instance
this.connectionManager = RedisConnectionManager.getInstance();
@ -47,6 +47,7 @@ export class RedisCache implements CacheProvider {
name: `${baseName}-SERVICE`,
singleton: options.shared ?? true, // Default to shared connection for cache
redisConfig: options.redisConfig,
logger: this.logger,
});
// Only setup event handlers for non-shared connections to avoid memory leaks