npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-redis-retry-strategy

v2.1.1

Published

My custom node_redis retry_strategy function

Downloads

7,887

Readme

node-redis-retry-strategy

License: MIT Build Status codecov Dependencies install size

A custom implementation of the node_redis retry_strategy function.

Sometimes, if the Redis server is down, you need to have clients that don't give up and try to reconnect.
"node-redis-retry-strategy" is a function that returns the node_redis retry_strategy function. The strategy is: every wait_time try to connect for number_of_retry_attempts times (each time separated by delay_of_retry_attempts). By default, every 5 minutes, try 5 times to reconnect (every attempt is separated by 500 ms). It retries forever.

* 2.0 breaking change: by default do not allow to start the service without a redis connection; to have the previous behaviour set allow_to_start_without_connection:true

Install

# with npm
npm install node-redis-retry-strategy

# or with yarn
yarn add node-redis-retry-strategy

Usage

// redisClient.js file
var redis = require("redis");
var retryStrategy = require("node-redis-retry-strategy");

var client = redis.createClient({
    host: "127.0.0.1",
    port: 6379,
    retry_strategy: retryStrategy()
});

module.exports = client;
// index.js file
var redisClient = require("redisClient.js");

redisClient.on("connect", function () {
    console.log("connected!");
});
redisClient.on("end", function () {
    console.log("redis connection has closed");
});
redisClient.on("reconnecting", function (o) {
    console.log("redis client reconnecting", o.attempt, o.delay);
});

Options

It accepts options object as a parameter with 4 possible keys:

allow_to_start_without_connection type boolean

Default: false 2 possible scenarios:

  • false if there is no connection when the service starts, end reconnecting throwing an error and flush all commands
  • true allow to start the service without a redis connection
var redis = require("redis");
var retryStrategy = require("node-redis-retry-strategy");

var client = redis.createClient({
    host: "127.0.0.1",
    port: 6379,
    retry_strategy: retryStrategy({
        allow_to_start_without_connection: true
    })
});

module.exports = client;

number_of_retry_attempts type number ms

Default: 5
The number of attempts separated by the delay_of_retry_attempts. If set to 0, it ends reconnecting with the built in error.

var redis = require("redis");
var retryStrategy = require("node-redis-retry-strategy");

var client = redis.createClient({
    host: "127.0.0.1",
    port: 6379,
    retry_strategy: retryStrategy({
        number_of_retry_attempts: 7
    })
});

module.exports = client;

delay_of_retry_attempts type number ms

Default: 500
The delay between each retry attempts.

var redis = require("redis");
var retryStrategy = require("node-redis-retry-strategy");

var client = redis.createClient({
    host: "127.0.0.1",
    port: 6379,
    retry_strategy: retryStrategy({
        delay_of_retry_attempts: 1000
    })
});

module.exports = client;

wait_time type number ms

Default: 300000 (5 min)
How long stop retrying to connect.

var redis = require("redis");
var retryStrategy = require("node-redis-retry-strategy");

var client = redis.createClient({
    host: "127.0.0.1",
    port: 6379,
    retry_strategy: retryStrategy({
        wait_time: 600000
    })
});

module.exports = client;

License

MIT