@xnestjs/ioredis
v1.12.3
Published
NestJS extension library for ioredis
Readme
@xnestjs/ioredis
NestJS extension library for ioredis
Install
npm install @xnestjs/ioredis
# or using yarn
yarn add @xnestjs/ioredisUsage
Register standalone sync
An example of nestjs module that creates RedisClient with standalone connection.
// module.ts
import { Module } from '@nestjs/common';
import { RedisModule } from '@xnestjs/ioredis';
@Module({
imports: [
RedisModule.forRoot({
useValue: {
host: 'localhost',
port: 6379,
},
}),
],
})
export class MyModule {}Register cluster sync
An example of nestjs module that creates RedisClient with cluster connection.
// module.ts
import { Module } from '@nestjs/common';
import { RedisModule } from '@xnestjs/ioredis';
@Module({
imports: [
RedisModule.forRoot({
useValue: {
nodes: ['localhost'],
},
}),
],
})
export class MyModule {}Register standalone async
An example of nestjs module that creates RedisClient with standalone connection async
// module.ts
import { Module } from '@nestjs/common';
import { RedisModule } from '@xnestjs/ioredis';
@Module({
imports: [
ElasticsearchModule.forRootAsync({
inject: [ConfigModule],
useFactory: (config: ConfigService) => ({
host: config.get('REDIS_HOST'),
}),
}),
],
})
export class MyModule {}Register cluster async
An example of nestjs module that creates RedisClient with cluster connection async
// module.ts
import { Module } from '@nestjs/common';
import { RedisModule } from '@xnestjs/ioredis';
@Module({
imports: [
ElasticsearchModule.forRootAsync({
inject: [ConfigModule],
useFactory: (config: ConfigService) => ({
nodes: config.get('REDIS_NODES'),
}),
}),
],
})
export class MyModule {}Environment Variables
The library supports configuration through environment variables. Environment variables below is accepted. All environment variables starts with prefix (REDIS_). This can be configured while registering the module.
