npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ms-redis-cliente

v0.0.82

Published

Paquete de Conexion para interceptar datos de respuesta y guardar la informacion en REDIS-CACHE

Downloads

15

Readme

Descripcion

Paquete de Conexion para interceptar datos de respuesta y guardar la informacion en REDIS-CACHE

Instalacion

Instalacion del paquete

npm i ms-redis-cliente/redis

Configuracion

Configuracion de Paquete en el archivo app.module.ts

import { AppModuleRedisClient, DatapassInterceptor } from 'ms-redis-cliente'
@Module({
  imports: [
    AppModuleRedisClient.register(),
  ],
  controllers: [], 
  providers: [
    DatapassInterceptor
  ],
})
export class AppModule {}

Configuracion de Paquete en el archivo my.montroller.ts

import { DatapassInterceptor } from 'ms-redis-cliente'

 @Get('/my-rest-api') 
 @SetMetadata("data-cache", {key:"key-name-cache",ttl:15}) 
 @UseInterceptors(DatapassInterceptor)
 /*Configuracion de Res() obligatoria
    { passthrough: true }
 Configuracion de Res() obligatoria*/
 async myRestApi(@Res({ passthrough: true }) res) {
    try {
        /*Configuracion de respuesta obligatoria*/
        const getResponse = await this.appService.getRestApiTWo()
        return getResponse
        /*Configuracion de respuesta obligatoria*/
    } catch (error) {
        return res.status(HttpStatus.BAD_REQUEST).json(error);
    }
 }

Propiedades del decorador @SetMetadata("data-cache")

Descripcion de los campos en "data-cache"

| Propiedad | Valor | Descripcion | | ------ | ------ | ------ | | key | String (null) | key de donde se guardara los datos guardados CAMPO OBLIGATORIO SI useKeyUrl es FALSE | | ttl | Number (0)| Tiempo de vida del cache almacenar | | keyResponse | String (null) | Propiedad de respuesta de los datos del controlador | | useKeyUrl | Boolean (false) | Si es TRUE tomara la URL del controlador como key para guardar los datos en cache| | ignoreExceptions | Boolean | Ignora exepciones del servidor de ms-redis | | responseHttp | Boolean(true) | Respuesta del interceptor por HTTP declare en falso si tiene otros interceptores http o respuestas ya generadas y enviadas al cliente por http |

Uso del Servicio

Se pueden utilizar el servicio

Debe realizar la configuracion de Paquete en su archivo my.service.ts

import { AppServiceRedisClient } from 'ms-redis-cliente'

@Injectable()
export class AppService {
  constructor(
    private appServiceRedisClient:AppServiceRedisClient
  ){}

  //Se utilizo Observable<AxiosResponse<any[]>> solo por fines de desarrollo para consumir un RESTAPI
  async mySetCache():Promise<Observable<AxiosResponse<any[]>>>{
    try {
        const response = await this.httpService.get(`https://pokeapi.co/api/v2/pokemon/ditto`).toPromise()
        //this.appServiceRedisClient.SetCache(key,value,ttl)
        await this.appServiceRedisClient.SetCache("key",JSON.stringify(response.data),150)
        return response.data
    } catch (error) {
        throw error
    }
  }

    async myGetCache():Promise<any>{
    try {
        //this.appServiceRedisClient.getCache(key)
        const getData = await this.appServiceRedisClient.getCache("key")
        return getData
    } catch (error) {
        throw error
    }
  }
    
  async myDeleteCache():Promise<any>{
    try {
        //this.appServiceRedisClient.DeleteCache(key)
        await this.appServiceRedisClient.DeleteCache("key")
    } catch (error) {
        throw error
    }
  }
}

Descripcion de los parametos en los servicios

| Propiedad | Valor | Descripcion | | ------ | ------ | ------ | | key | String (null) | key identificador para realizar Guardar, Recuperar o Eliminar en redis| | value | String(null)| Valor almacenar en Redis | | ttl | Number (0)| Tiempo de vida del cache almacenar |

Uso del Interceptor desde el Fronted

Se pueden utilizar las siguientes propiedades desde el frontend en el QUERY de una solicitud HTTP | Propiedad | Valor | Descripcion | | ------ | ------ | ------ | | noCache | Boolean (false) | Si el valor es TRUE ignora el cache almacenado en redis | | ttl | Number (0)| Tiempo de vida del cache a almacenar |

Configuracion en solicitud HTTP

Caso 1, Ignorar Cache:

curl --location 'https://my-rest-api.com/rest-api-two?noCache=true

Caso 2, Control de tiempo de vida del cache en segundos:

curl --location 'https://my-rest-api.com/rest-api-two?ttl=60

Recalcar que la propiedad ${TTL} del frontend tiene prioridad al ${TTL} del backend del @SetMetadata("data-cache")