@medusajs/locking
v2.22.7
Published
Locking Module for Medusa
Keywords
Readme
Locking Module for Medusa: acquires and releases locks on shared resources so that only one process runs a critical section at a time, preventing race conditions such as overselling inventory. Locks are handled by Locking Module Providers: an in-memory provider is built in, and Postgres or Redis providers coordinate locks across multiple instances. It ships with @medusajs/medusa and is registered by default; use it with the acquireLockStep and releaseLockStep workflow steps, or resolve it with container.resolve(Modules.LOCKING).
At a glance
| | |
| --- | --- |
| Package | @medusajs/locking |
| Type | Infrastructure Module |
| Module key | Modules.LOCKING ("locking") |
| Registered by default | Yes (in-memory provider; Redis provider on Medusa Cloud when REDIS_URL is set) |
Providers
The module accepts multiple providers. The built-in in-memory provider (in-memory) is always registered and is the default when you don't register others. Official providers:
| Package | Register with |
| --- | --- |
| @medusajs/locking-postgres | @medusajs/medusa/locking-postgres |
| @medusajs/locking-redis | @medusajs/medusa/locking-redis |
Installation
No installation needed. The module ships with @medusajs/medusa.
Usage
import { defineConfig } from "@medusajs/framework/utils"
module.exports = defineConfig({
// ...
modules: [
{
resolve: "@medusajs/medusa/locking",
options: {
providers: [
{
resolve: "@medusajs/medusa/locking-redis",
id: "locking-redis",
is_default: true,
options: {
redisUrl: process.env.LOCKING_REDIS_URL,
},
},
],
},
},
],
})Configuration
| Option | Type | Description | Default |
| --- | --- | --- | --- |
| providers | { resolve: string, id: string, is_default?: boolean, options?: Record<string, unknown> }[] | Locking providers to register. When only one provider is registered, or one sets is_default: true, it becomes the default. | [] (in-memory provider is used) |
