Skip to content

Commit

Permalink
Include expected resource keys format on README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
BernalCarlos committed Feb 13, 2024
1 parent 5138813 commit e1b886f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ The `using` method wraps and executes a routine in the context of an auto-extend

The first parameter is an array of resources to lock; the second is the requested lock duration in milliseconds, which MUST NOT contain values after the decimal.

The resources keys must follow the convention `key:value`, where `key` is a unique identifier for the resource and `value` is the value of the resource. For example, if you are doing a lock based on a user's account id, you might use `account:123` as the resource key.

```ts
await redlock.using([senderId, recipientId], 5000, async (signal) => {
await redlock.using([`senderId:${senderId}`, `recipientId:${recipientId}`], 5000, async (signal) => {
// Do something...
await something();

Expand All @@ -85,7 +87,7 @@ Alternatively, locks can be acquired and released directly:

```ts
// Acquire a lock.
let lock = await redlock.acquire(["a"], 5000);
let lock = await redlock.acquire(["resource-key:resource-value"], 5000);
try {
// Do something...
await something();
Expand Down

0 comments on commit e1b886f

Please sign in to comment.