1.0.3 • Published 3 years ago

@luckbox/redis v1.0.3

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

node-redis

A wrapper that handles some of the connection deficiencies of the "redis" 2.x.x package.

Motivation

When using Redis in a high-availability environment, one might find that in some cases the NodeRedis's retry_strategy might not provide enough flexibility. If the server does not come back before the next reconnection attempt happens, the client hangs until the underlying socket times out, usually 120 seconds - the system's default. If however, the connection_timeout is lowered so that the the reconnection attempts are given up on sooner, once the socket times out no further attempts are made, rendering the retry_strategy useless.

Usage

This wrapper can be used as a drop in replacement for the NodeRedis library, as it exposes the same API interface.

Example

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

const client = redis.createClient({
  host: '127.0.0.1',
  port: 6379,
  heartbeat_interval: 10000,
  heartbeat_timeout: 5000
});

client.on('heartbeat-timeout', error => {
  console.warn('Connection to Redis lost. Retrying...', error);
});

client.set('myKey', 'foo', redis.print);
...

API

For general usage, refer to the official documentation.

The following additional functionality has been added:

Initialization options

NameDefaultDescription
heartbeat_interval5000How often to check the connection's health in milliseconds
heartbeat_timeout1000How long before a heartbeat times out in milliseconds

Events

heartbeat-timeout client will emit heartbeat-timeout when the last heartbeat has timed out.

1.0.3

3 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago