@abeai/redis

Wrapper for NodeRedis including node-redlock.

Usage no npm install needed!

<script type="module">
  import abeaiRedis from 'https://cdn.skypack.dev/@abeai/redis';
</script>

README

Wrapper for NodeRedis including node-redlock.

Overview

The redis module provides promisified redis command functions along with an implementation of the Redlock algorithm.

Installation

npm install @abeai/redis --save

Instantiation

const redis = require('@abeai/redis');

redis.init(host, options);
redis.client().get('some_key')
    .then((value) => {

        console.log(value);

    })
    .catch((err) => {

        console.log(err, 'Failed to get some_key');

    })
;

Interface

init(host[, options])

Creates a new redis client instance which includes an instance of the node-redlock module.

Options

redis

Key value dictionary of NodeRedis options.

redlock

Key value dictionary of node-redlock options.

client()

Returns the redis client instance which includes all standard redis commands via NodeRedis as described here. The command function names are lowercase and all functions return a promise.

While this package does use NodeRedis under the hood, the client's promisified function names do not include the 'Async' suffix as described in the NodeRedis documentation.

This document will only cover client functions not related to redis commands as this information is widely available elsewhere.

client.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 promise returning function that should be executed while the resource is locked.

client.error(...args)

Main error handler used for error events over the lifetime of the redis connection and Redlock handling. Override this function to provide custom error handling logic.

This function should not be called directly.

client.retry(options)

Main retry handler used for connection error events over the lifetime of the redis connection. Override this function to provide custom retry handling logic.

This function is directly implemented by the underlying NodeRedis instance as its retry strategy and as such its implementation details can be found here under the retry_strategy option.

This function should not be called directly.