Wondering what’s next for npm?Check out our public roadmap! »

    @abeai/node-redlock

    1.1.0 • Public • Published

    Wrapper for node-redlock.

    Overview

    This package provides a pragmatic interface on top of node-redlock.

    Installation

    npm install @abeai/node-redlock --save

    Instantiation

    const Redlock = require('@abeai/node-redlock');
    const redis = require('@abeai/node-redlock');
    
    redis.init(host, options);
    
    const redlock = new Redlock(redis.client());
    
    redlock.lock('lockkey', 1000, () => {
        ...
    });

    Interface

    Redlock(redisClients[, options])

    Creates a new redlock instance.

    redisClients can be a single Redis client or an array of Redis clients.

    Options

    defaultTtl

    Default TTL in ms which should be used if ttl is obmitted in redlock.lock call.

    driftFactor

    The expected clock drift in ms. Default: 0.01

    For more details see http://redis.io/topics/distlock.

    retryCount

    The max number of times Redlock will attempt to lock a resource before erroring. Default: 300

    retryDelay

    The time in ms between attempts. Default: 50

    retryJitter

    The max time in ms randomly added to retries to improve performance under high contention. Default: 50

    For more details see https://www.awsarchitectureblog.com/2015/03/backoff.html.

    redlock.lock(resource[, ttl], fn)

    Locks a given resource using the Redlock algorithm. Accepts a resource string, TTL of milliseconds that the lock should be held, and a function that should be executed while the resource is locked.

    If ttl is obmitted, options.defaultTtl is used instead.

    Keywords

    Install

    npm i @abeai/node-redlock

    DownloadsWeekly Downloads

    142

    Version

    1.1.0

    License

    none

    Unpacked Size

    12.7 kB

    Total Files

    12

    Last publish

    Collaborators

    • avatar
    • avatar