Get started with Verrou locking library
mainVerrou is a locking library for Node.js designed to provide a consistent API across different storage backends. It allows you to manage distributed locks using various drivers such as Redis, Postgres, MySQL, Sqlite, or In-Memory.
A key advantage is the ability to switch drivers (e.g., using Redis in production and an In-Memory driver for fast, infrastructure-free testing) without changing your application logic.
// See Basic usage for a concrete example
```ts
import { Verrou } from '@verrou/core'
import { redisStore } from '@verrou/core/drivers/redis'
import { memoryStore } from '@verrou/core/drivers/memory'
const verrou = new Verrou({
default: 'redis',
stores: {
redis: { driver: redisStore() },
memory: { driver: memoryStore() }
}
})
// Lock a resource and run a function
await verrou.createLock('my-resource').run(async () => {
await doSomething()
}) // Lock is automatically released