refactoring continuing
This commit is contained in:
parent
742e590382
commit
a0a3b26177
20 changed files with 394 additions and 798 deletions
9
libs/data/cache/src/connection-manager.ts
vendored
9
libs/data/cache/src/connection-manager.ts
vendored
|
|
@ -1,5 +1,4 @@
|
|||
import Redis from 'ioredis';
|
||||
import { getLogger } from '@stock-bot/logger';
|
||||
import type { RedisConfig } from './types';
|
||||
|
||||
interface ConnectionConfig {
|
||||
|
|
@ -7,6 +6,7 @@ interface ConnectionConfig {
|
|||
singleton?: boolean;
|
||||
db?: number;
|
||||
redisConfig: RedisConfig;
|
||||
logger?: any;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -16,7 +16,7 @@ export class RedisConnectionManager {
|
|||
private connections = new Map<string, Redis>();
|
||||
private static sharedConnections = new Map<string, Redis>();
|
||||
private static instance: RedisConnectionManager;
|
||||
private logger = getLogger('redis-connection-manager');
|
||||
private logger: any = console;
|
||||
private static readyConnections = new Set<string>();
|
||||
|
||||
// Singleton pattern for the manager itself
|
||||
|
|
@ -33,7 +33,10 @@ export class RedisConnectionManager {
|
|||
* @returns Redis connection instance
|
||||
*/
|
||||
getConnection(config: ConnectionConfig): Redis {
|
||||
const { name, singleton = false, db, redisConfig } = config;
|
||||
const { name, singleton = false, db, redisConfig, logger } = config;
|
||||
if (logger) {
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
if (singleton) {
|
||||
// Use shared connection across all instances
|
||||
|
|
|
|||
5
libs/data/cache/src/redis-cache.ts
vendored
5
libs/data/cache/src/redis-cache.ts
vendored
|
|
@ -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
|
||||
|
|
|
|||
1
libs/data/cache/src/types.ts
vendored
1
libs/data/cache/src/types.ts
vendored
|
|
@ -85,6 +85,7 @@ export interface CacheOptions {
|
|||
name?: string; // Name for connection identification
|
||||
shared?: boolean; // Whether to use shared connection
|
||||
redisConfig: RedisConfig;
|
||||
logger?: any; // Optional logger instance
|
||||
}
|
||||
|
||||
export interface CacheStats {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue