@strongnguyen/nestjs-ioredis
v1.0.7
Published
Nest - a ioredis module (@ioredis)
Downloads
117
Maintainers
Readme
Installation
with npm
npm install --save @nestjs-modules/ioredis ioredis
with yarn
yarn add @nestjs-modules/ioredis ioredis
How to use?
RedisModule.forRoot(options, connection?)
import { Module } from '@nestjs/common';
import { RedisModule } from '@nestjs-modules/ioredis';
import { AppController } from './app.controller';
@Module({
imports: [
RedisModule.forRoot({
config: {
url: 'redis://localhost:6379',
},
}),
],
controllers: [AppController],
})
export class AppModule {}
RedisModule.forRootAsync(options, connection?)
import { Module } from '@nestjs/common';
import { RedisModule } from '@nestjs-modules/ioredis';
import { AppController } from './app.controller';
@Module({
imports: [
RedisModule.forRootAsync({
useFactory: () => ({
config: {
url: 'redis://localhost:6379',
},
}),
}),
],
controllers: [AppController],
})
export class AppModule {}
InjectRedis(connection?)
import { Controller, Get, } from '@nestjs/common';
import { InjectRedis, Redis } from '@nestjs-modules/ioredis';
@Controller()
export class AppController {
constructor(
@InjectRedis() private readonly redis: Redis,
) {}
@Get()
async getHello() {
await this.redis.set('key', 'Redis data!');
const redisData = await this.redis.get("key");
return { redisData };
}
}
License
MIT