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

nest-rest-framework-redis

v1.0.0

Published

Nest Redis Librarry

Downloads

3

Readme

CircleCI

Description

Nest-Rest-Framework-Redis manages your REDIS CRUD for you. Need a super fast Key-Value store for some of your data, but don't want to sacrficie REST conventions? Try our framework

Installation

$ npm install --save nest-rest-framework nest-rest-framework-redis

Usage

See the example Directory.

Like All Nest Rest Framework implementations, you start with a model.

export class ExampleModel {
  id: string;
  firstName: string;
  lastName: string;
  age: number;
}

Then you define a ViewSet that Extends RedisViewSet. The Class should be injectible. The redisRepository injected will be provided by a Global Export from the NestRestFrameworkRedisModule. The second argument is the type you want to save. The third argument is the property inside that object represeting the Key, redis is a key/value store. This can also be a function which return a string. The final argument is a prefix to use for the Type. If you want to colocate multiple types in one redis cluster then using a prefix specific to each type helps

import { Injectable } from '@nestjs/common';
import { RedisViewSet, RedisRepository } from 'nest-rest-framework-redis';
import { ExampleModel } from './example-model';

@Injectable()
export class ExampleViewSet extends RedisViewSet<ExampleModel> {
  constructor(readonly redisRepository: RedisRepository) {
    super(
      redisRepository, // The Redis Repository
      ExampleModel, // The Example Model you want to svae
      'id', // The property of ExampleModel representing the primaryKey
      'example_', // The Prefix for distinguishing keys of different data types in Redis.
    );
  }
}

Then you define a controller that injects that ViewSet. It needs to be decorated as a controller. You can review the other options which can be injected into the RestController. They essentially allow you to do any business logic necessary at all points of the request lifecycle.

import { Controller } from '@nestjs/common';
import { RestController } from 'nest-rest-framework';
import { ExampleModel } from './example-model';
import { ExampleViewSet } from './example-view-set';

@Controller('example')
export class ExampleController extends RestController<
  string,
  ExampleModel,
  ExampleModel,
  ExampleModel
> {
  constructor(readonly exampleViewSet: ExampleViewSet) {
    super({
      viewset: exampleViewSet,
    });
  }
}

Finally import NestRestFrameworkRedisModule in your app module. It will provide the RedisRepository you need. The forRoot method takes ClientOps arguments from the node redis lib. The second argument is whether you want to run a local in-memroy mock-redis server for testing. We found the library very, very useful.

import { Module } from '@nestjs/common';
import { ExampleController } from './example.controller';
import { ExampleViewSet } from './example-view-set';
import { NestRestFrameworkRedisModule } from 'nest-rest-framework-redis';

@Module({
  imports: [
    NestRestFrameworkRedisModule.forRoot(
      {
        host: 'localhost',
        port: 66666,
        password: 'fakepassword',
      },
      true,
    ),
  ],
  controllers: [ExampleController],
  providers: [ExampleViewSet],
})
export class ExampleModule {}

Stay in touch

License

Nest-Rest-Framework-Redis is MIT licensed.