📝Hyperc

The module provides a simple way to cache data in Redis.

Imports

import { HypercService } from 'niro-health';

Method of Use

To use this module, you need to inject it into the desired service.

import { Module } from '@nestjs/common';
import {
  RedisService,
  DebugService,
  ConfigurationService,
  ValidatorRegexpService,
  StringExService,
} from 'niro-health';
import { AppController } from './app.controller';
import { AppService } from './app.service';

@Module({
  controllers: [AppController],
  providers: [
    AppService,
    {
      provide: 'IRedisService',
      useClass: RedisService,
    },
    {
      provide: 'IDebugService',
      useClass: DebugService,
    },
    {
      provide: 'IConfigurationService',
      useClass: ConfigurationService,
    },
    {
      provide: 'IValidatorRegexpService',
      useClass: ValidatorRegexpService,
    },
    {
      provide: 'IStringExService',
      useClass: StringExService,
    },    
  ],
})
export class AppModule {}

Injecting the module into our service.

import { Inject, Injectable } from '@nestjs/common';
import type { IHypercService } from 'niro-health';

@Injectable()
export class AppService {
  constructor(
    @Inject('IHypercService')
    private readonly hypercService: IHypercService,
  ) {}

  public create() {
    return this.hypercService.create('Hello World', 1000);
  }
}

With dependencies

You will need to inject the following interfaces.

Interface
Service

IConfigurationService

IValidatorRegexpService

IStringExService

IRedisService

IDebugService

Methods

Method
Scope
Description

_nameExpire

private

Returns the name expire of the cache serialized.

_nameKey

private

Returns the name key of the cache serialized.

_isExpired

private

Check if the cache is expired.

create

public

Create a new cache with a ttl in milliseconds (ms).

set

public

Set a new value in the cache.

get

public

Get a value from the cache.

del

public

Delete a value from the cache.

flush

public

Delete all values from the cache.

flushAll

public

Delete all values from all caches.

Last updated