Skip to content

a few issues after trying beta 5.0.0 #297

@pdeveltere

Description

@pdeveltere

Hi,

We are using redlock in a big project, and I started looking into upgrading since we want to upgrade ioredis to v5. A few suggestions:

  1. can we have a double signature on the acquire function so it accepts both a string and an array of strings. this will make migrating much easier for most users. And I think in general the more common usecase will be a lock on 1 resource:
public async acquire(
    resources: string | string[],
  1. why can the lock.release() still throw an error? in the examples you put lock.release() in the finally section, however this function can also throw an ExecutionError. So we would have to do something like this:
    let lock: Lock | null = null;
    try {
      lock = await redLock.acquire([`...`], 15000);
      // do some stuff
    } catch (error) {
      if (error instanceOf ResourceLockedError) {
        console.log('failed to acquire the lock on the resource');
      }
      console.log(error)
    } finally {
      await lock?.release().catch(ExecutionError, () => {
        console.log('failed to release the lock on the update. This can indicate that the lock expired prior to unlocking it');
      });
    }

this makes everything a bit convoluted. I would let the release of the lock fail silently.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions