0.2.4 • Published 2 years ago

@blastz/nest-redlock v0.2.4

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

nest-redlock

Redlock module for Nest.

Installation

npm install @elaina/nest-redlock

Usage

// app.module.ts
import { RedlockModule } from "nest-redlock";

@Module({
  imports: [
    RedlockModule.forRoot({
      clients: [
        {
          host: "localhost",
          port: 6379,
        },
      ],
    }),
  ],
})
export class AppModule {}

// example.service.ts
import { RedlockService } from "nest-redlock";

@Injectable()
export class ExampleService {
  constructor(private redlockService: RedlockService) {}

  async test(param: string) {
    const lock = await this.redlockService.acquire([`test:${param}`], 5000);

    try {
      // ...
    } finally {
      await lock.release();
    }
  }
}