@nestjs-redisx/locks
v1.0.3
Published
Distributed locks plugin for NestJS RedisX with auto-renewal and retry strategies
Maintainers
Readme
@nestjs-redisx/locks
Distributed locks plugin for NestJS RedisX. Provides @WithLock decorator and LockService with auto-renewal, retry strategies, and dead-lock prevention via TTL.
Installation
npm install @nestjs-redisx/core @nestjs-redisx/locks ioredisQuick Example
import { RedisModule } from '@nestjs-redisx/core';
import { LocksPlugin, WithLock } from '@nestjs-redisx/locks';
@Module({
imports: [
RedisModule.forRoot({
clients: { host: 'localhost', port: 6379 },
plugins: [new LocksPlugin({ defaultTtl: 30000 })],
}),
],
})
export class AppModule {}
@Injectable()
export class PaymentService {
@WithLock({ key: 'payment:{0}', ttl: 10000 })
async processPayment(orderId: string) {
// Only one instance processes this order at a time
}
}Documentation
Full documentation: nestjs-redisx.dev/en/reference/locks/
License
MIT
