> ## Documentation Index
> Fetch the complete documentation index at: https://nestcrate.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# nestrs-locks API

> Reference for LocksModule, LocksService, LockGuard, and lock stores.

Crate: [`nestrs-locks`](https://docs.rs/nestrs-locks/1.7.1) · Feature: `locks` · Guide: [Locks](https://nestcrate.dev/ecosystem/locks.md)

```toml theme={null}
nestrs-locks = "1.7.1"
```

## `LocksModule::register`

Exports `LocksService` and `LocksOptions`.

## `LocksService`

```rust theme={null}
pub fn from_options(opts: &LocksOptions) -> Self
pub async fn try_acquire(&self, name: &str) -> Option<LockGuard>
pub async fn with_lock<F, Fut, T>(&self, name: &str, f: F) -> Option<T>
```

`LockGuard::release().await` frees the lease early; drop may also release depending on store.

## `LocksOptions`

| Field | Default |
| - | - |
| `store` | in-memory |
| `default_ttl` | 30s |

Optional Redis: feature `cache-redis` → `RedisLockStore`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.