@abeai/node-redis

Wrapper for NodeRedis.

Usage no npm install needed!

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

README

Wrapper for ioredis.

Overview

The redis module provides promisified redis commands.

Installation

npm install @abeai/node-redis

Instantiation

With afterInitialization hook

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

redis.init(host, options);

// Will wait until the redis client is created and connected to server
redis.afterInitialization(function() {
    redis.client().get('some_key')
        .then((value) => {
            console.log(value);
        })
        .catch((err) => {
            console.log(err, 'Failed to get some_key');
        })
    ;
});

Without afterInitialization hook

const redis = require('@abeai/node-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.

Options

redis

Key value dictionary of ioredis options.

logger

Custom logger to be used by client.

client()

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

afterInitialization()

Handler attached to the underlying redis client's ready event. This is only called once when the client connects to the server for the first time.

onReady()

Handler attached to the underlying redis client's ready event. This is called every time the client connects to the server including reconnects.