Skip to content

🙈 🙉 🙊 A ioredis module for Nest framework (node.js)

License

Notifications You must be signed in to change notification settings

mr-yum/nestjs-modules__ioredis

 
 

Repository files navigation

Nest Logo

A ioredis module for Nest framework (node.js) using ioredis library

NPM Version Package License NPM Downloads

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

About

🙈 🙉 🙊 A ioredis module for Nest framework (node.js)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 86.3%
  • JavaScript 12.6%
  • Shell 1.1%