@blastz/nest-redlock
v0.2.4
Published
nest redlock module
Downloads
1,299
Maintainers
Readme
nest-redlock
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();
}
}
}