
Product
Introducing Tier 1 Reachability: Precision CVE Triage for Enterprise Teams
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
nest-rest-framework-redis
Advanced tools
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
$ npm install --save nest-rest-framework nest-rest-framework-redis
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 {}
Nest-Rest-Framework-Redis is MIT licensed.
FAQs
Nest Redis Librarry
We found that nest-rest-framework-redis demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.