A ioredis module for Nest framework (node.js) using ioredis library
npm install --save @nestjs-modules/ioredis ioredis
yarn add @nestjs-modules/ioredis ioredis
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 {}
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 {}
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 };
}
}
MIT