Socket
Book a DemoInstallSign in
Socket

@hemia/cache-manager

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hemia/cache-manager

Manejador de caché con soporte Redis y tsyringe

0.0.1
latest
npmnpm
Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

@hemia/cache-manager

Una librería sencilla y extensible para manejar caché utilizando Redis a través de ioredis, con soporte completo para inyección de dependencias mediante tsyringe. Incluye operaciones comunes como almacenamiento de cadenas, objetos, listas, TTL, incremento y más.

Instalación

npm install @hemia/cache-manager

Configuración y DI (tsyringe)

Crea el archivo:

src/config/di/CacheContainer.ts
import { container } from 'tsyringe';
import { CacheClient, CacheService, RedisConfig } from '@hemia/cache-manager';

const redisConfig: RedisConfig = {
  host: process.env.REDIS_HOST || '127.0.0.1',
  port: Number(process.env.REDIS_PORT) || 6379,
  password: process.env.REDIS_PASSWORD,
  db: Number(process.env.REDIS_DB) || 0,
  tls: process.env.REDIS_TLS === 'true',
};

container.register<CacheClient>('CacheClient', {
  useFactory: () => new CacheClient(redisConfig),
});

container.registerSingleton<CacheService>('CacheService', CacheService);

export default container;

Ejemplo de uso con inyección

import { injectable, inject } from 'tsyringe';
import { CacheService } from '@hemia/cache-manager';

@injectable()
export class ResourceController {
  constructor(
    @inject('CacheService') private cacheService: CacheService,
    @inject('InjectedString') private injectedString: string
  ) {}
}

Métodos disponibles

setString(key: string, value: string | number, expireTime?: number): Promise<void>
getString(key: string): Promise<string | null>

setObject<T>(key: string, value: T, expireTime?: number): Promise<void>
getObject<T>(key: string): Promise<T | null>

setList(key: string, value: string | number): Promise<void>
getList(key: string, start?: number, stop?: number): Promise<string[]>

deleteKey(key: string): Promise<void>
expire(key: string, seconds: number): Promise<void>
exists(key: string): Promise<boolean>

increment(key: string): Promise<number>
decrement(key: string): Promise<number>
getKeysByPattern(pattern: string): Promise<string[]>
getTTL(key: string): Promise<number>

Configuración de Redis

interface RedisConfig {
  host: string;
  port: number;
  username?: string;
  password?: string;
  db: number;
  tls?: boolean;
}

Licencia

MIT — © Hemia Technologies

Desarrollado por Hemia Technologies

Keywords

redis

FAQs

Package last updated on 01 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.