| 1 | import { DynamicModule, Module } from '@nestjs/common' |
| 2 | import { RedisModule } from '@yikart/redis' |
| 3 | import { RedlockConfig } from './redlock.config' |
| 4 | import { RedlockInjector } from './redlock.injector' |
| 5 | import { RedlockService } from './redlock.service' |
| 6 | |
| 7 | @Module({}) |
| 8 | export class RedlockModule { |
| 9 | static forRoot(config: RedlockConfig): DynamicModule { |
| 10 | return { |
| 11 | module: RedlockModule, |
| 12 | imports: [ |
| 13 | RedisModule.forRoot(config.redis), |
| 14 | ], |
| 15 | providers: [ |
| 16 | { |
| 17 | provide: RedlockConfig, |
| 18 | useValue: config, |
| 19 | }, |
| 20 | RedlockService, |
| 21 | RedlockInjector, |
| 22 | ], |
| 23 | exports: [RedlockService], |
| 24 | global: true, |
| 25 | } |
| 26 | } |
| 27 | } |
| 28 |