nest-redlock
v0.2.0
Published
nest redlock module
Downloads
189
Readme
nest-redlock
Installation
npm install 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();
}
}
}